Skip to content

Commit

Permalink
call nexttick before entering wait in mach port
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerwang committed Aug 30, 2014
1 parent fa4dc38 commit 8c5bc86
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
5 changes: 3 additions & 2 deletions base/message_loop/message_pump_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class MessagePumpCFRunLoopBase : public MessagePump {
// Needs access to CreateAutoreleasePool.
friend class MessagePumpScopedAutoreleasePool;
public:
MessagePumpCFRunLoopBase();
MessagePumpCFRunLoopBase(bool forNode = false);
virtual ~MessagePumpCFRunLoopBase();

// Subclasses should implement the work they need to do in MessagePump::Run
Expand Down Expand Up @@ -203,6 +203,7 @@ class MessagePumpCFRunLoopBase : public MessagePump {
bool delegateless_work_;
bool delegateless_idle_work_;

bool for_node_;
DISALLOW_COPY_AND_ASSIGN(MessagePumpCFRunLoopBase);
};

Expand All @@ -227,7 +228,7 @@ class MessagePumpCFRunLoop : public MessagePumpCFRunLoopBase {

class MessagePumpNSRunLoop : public MessagePumpCFRunLoopBase {
public:
BASE_EXPORT MessagePumpNSRunLoop();
BASE_EXPORT MessagePumpNSRunLoop(bool forNode = false);
virtual ~MessagePumpNSRunLoop();

virtual void DoRun(Delegate* delegate) OVERRIDE;
Expand Down
26 changes: 20 additions & 6 deletions base/message_loop/message_pump_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
#include <sys/event.h>
#include <sys/time.h>

#include "third_party/node/src/node.h"
#include "third_party/node/src/node_internals.h"

namespace {

void NoOp(void* info) {
Expand Down Expand Up @@ -291,14 +294,15 @@ void TimerFired() {
};

// Must be called on the run loop thread.
MessagePumpCFRunLoopBase::MessagePumpCFRunLoopBase()
MessagePumpCFRunLoopBase::MessagePumpCFRunLoopBase(bool forNode)
: delegate_(NULL),
delayed_work_fire_time_(kCFTimeIntervalMax),
nesting_level_(0),
run_nesting_level_(0),
deepest_nesting_level_(0),
delegateless_work_(false),
delegateless_idle_work_(false) {
delegateless_idle_work_(false),
for_node_(forNode) {
run_loop_ = CFRunLoopGetCurrent();
CFRetain(run_loop_);

Expand Down Expand Up @@ -656,6 +660,15 @@ void TimerFired() {
// Attempt to do some idle work before going to sleep.
self->RunIdleWork();

// call tick callback before sleep in mach port
// in the same way node upstream handle this in MakeCallBack,
// or the tick callback is blocked in some cases
if (node::g_env && self->for_node_) {
v8::Isolate* isolate = v8::Isolate::GetCurrent();
v8::HandleScope scope(isolate);
node::CallTickCallback(node::g_env, v8::Undefined(isolate));
}

// The run loop is about to go to sleep. If any of the work done since it
// started or woke up resulted in a nested run loop running,
// nesting-deferred work may have accumulated. Schedule it for processing
Expand Down Expand Up @@ -792,8 +805,8 @@ void TimerFired() {
}
}

MessagePumpNSRunLoop::MessagePumpNSRunLoop()
: keep_running_(true) {
MessagePumpNSRunLoop::MessagePumpNSRunLoop(bool forNode)
: MessagePumpCFRunLoopBase(forNode), keep_running_(true) {
CFRunLoopSourceContext source_context = CFRunLoopSourceContext();
source_context.perform = NoOp;
quit_source_ = CFRunLoopSourceCreate(NULL, // allocator
Expand Down Expand Up @@ -848,7 +861,8 @@ void TimerFired() {
#else

MessagePumpNSApplication::MessagePumpNSApplication(bool for_node)
: keep_running_(true),
: MessagePumpCFRunLoopBase(for_node),
keep_running_(true),
running_own_loop_(false),
pause_uv_(false),
for_node_(for_node) {
Expand Down Expand Up @@ -1112,7 +1126,7 @@ void TimerFired() {
#endif
}

return new MessagePumpNSRunLoop;
return new MessagePumpNSRunLoop(forNode);
}

} // namespace base

0 comments on commit 8c5bc86

Please sign in to comment.