From 9efde9577aefa7348f4274ee22f0fbadc90bab0e Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 23 Jul 2013 13:08:40 +0800 Subject: [PATCH] Move the watcher queue hack to NodeBindingsMac. It's mac only. --- common/node_bindings.cc | 19 ++++--------------- common/node_bindings.h | 6 +++--- common/node_bindings_mac.cc | 17 +++++++++++++++++ common/node_bindings_mac.h | 5 +++++ 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/common/node_bindings.cc b/common/node_bindings.cc index a8116026a78..0a4134173b8 100644 --- a/common/node_bindings.cc +++ b/common/node_bindings.cc @@ -134,10 +134,6 @@ void NodeBindings::RunMessageLoop() { // The MessageLoop should have been created, remember the one in main thread. message_loop_ = base::MessageLoop::current(); - // Get notified when libuv's watcher queue changes. - uv_loop_->data = this; - uv_loop_->on_watcher_queue_updated = OnWatcherQueueChanged; - // Run uv loop for once to give the uv__io_poll a chance to add all events. UvRunOnce(); } @@ -164,6 +160,10 @@ void NodeBindings::WakeupMainThread() { base::Unretained(this))); } +void NodeBindings::WakeupEmbedThread() { + uv_async_send(&dummy_uv_handle_); +} + // static void NodeBindings::EmbedThreadRunner(void *arg) { NodeBindings* self = static_cast(arg); @@ -179,15 +179,4 @@ void NodeBindings::EmbedThreadRunner(void *arg) { } } -// static -void NodeBindings::OnWatcherQueueChanged(uv_loop_t* loop) { - NodeBindings* self = static_cast(loop->data); - - DCHECK(!self->is_browser_ || BrowserThread::CurrentlyOn(BrowserThread::UI)); - - // We need to break the io polling in the kqueue thread when loop's watcher - // queue changes, otherwise new events cannot be notified. - uv_async_send(&self->dummy_uv_handle_); -} - } // namespace atom diff --git a/common/node_bindings.h b/common/node_bindings.h index 62d058658de..ef03424b85a 100644 --- a/common/node_bindings.h +++ b/common/node_bindings.h @@ -51,6 +51,9 @@ class NodeBindings { // Make the main thread run libuv loop. void WakeupMainThread(); + // Interrupt the PollEvents. + void WakeupEmbedThread(); + // Are we running in browser. bool is_browser_; @@ -64,9 +67,6 @@ class NodeBindings { // Thread to poll uv events. static void EmbedThreadRunner(void *arg); - // Called when uv's watcher queue changes. - static void OnWatcherQueueChanged(uv_loop_t* loop); - // Whether the libuv loop has ended. bool embed_closed_; diff --git a/common/node_bindings_mac.cc b/common/node_bindings_mac.cc index c092daeb3fb..3fe8eed0c9d 100644 --- a/common/node_bindings_mac.cc +++ b/common/node_bindings_mac.cc @@ -27,6 +27,23 @@ NodeBindingsMac::NodeBindingsMac(bool is_browser) NodeBindingsMac::~NodeBindingsMac() { } +void NodeBindingsMac::RunMessageLoop() { + // Get notified when libuv's watcher queue changes. + uv_loop_->data = this; + uv_loop_->on_watcher_queue_updated = OnWatcherQueueChanged; + + NodeBindings::RunMessageLoop(); +} + +// static +void NodeBindingsMac::OnWatcherQueueChanged(uv_loop_t* loop) { + NodeBindingsMac* self = static_cast(loop->data); + + // We need to break the io polling in the kqueue thread when loop's watcher + // queue changes, otherwise new events cannot be notified. + self->WakeupEmbedThread(); +} + void NodeBindingsMac::PollEvents() { struct timespec spec; int timeout = uv_backend_timeout(uv_loop_); diff --git a/common/node_bindings_mac.h b/common/node_bindings_mac.h index 6ae79c0a60b..4929c1a2cf6 100644 --- a/common/node_bindings_mac.h +++ b/common/node_bindings_mac.h @@ -15,7 +15,12 @@ class NodeBindingsMac : public NodeBindings { explicit NodeBindingsMac(bool is_browser); virtual ~NodeBindingsMac(); + virtual void RunMessageLoop() OVERRIDE; + private: + // Called when uv's watcher queue changes. + static void OnWatcherQueueChanged(uv_loop_t* loop); + virtual void PollEvents() OVERRIDE; // Kqueue to poll for uv's backend fd.