]> khamidou — GitHub mirrors - electron.git/commitdiff
Move the watcher queue hack to NodeBindingsMac.
authorCheng Zhao <zcbenz@gmail.com>
Tue, 23 Jul 2013 05:08:40 +0000 (13:08 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Tue, 23 Jul 2013 05:08:40 +0000 (13:08 +0800)
It's mac only.

common/node_bindings.cc
common/node_bindings.h
common/node_bindings_mac.cc
common/node_bindings_mac.h

index a8116026a789bae3f0562ecd0df5986b7c79b52c..0a4134173b81db804ec5951eb527a8b31b7c83c5 100644 (file)
@@ -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<NodeBindings*>(arg);
@@ -179,15 +179,4 @@ void NodeBindings::EmbedThreadRunner(void *arg) {
   }
 }
 
-// static
-void NodeBindings::OnWatcherQueueChanged(uv_loop_t* loop) {
-  NodeBindings* self = static_cast<NodeBindings*>(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
index 62d058658de2a84e3b6155e645526acaddbb70e8..ef03424b85a151ec3a92370e38345262baa2beff 100644 (file)
@@ -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_;
 
index c092daeb3fb9d9b6b70801ec9aea9ee40526e12e..3fe8eed0c9d2231c51168aad7b119f9dc3bd0ded 100644 (file)
@@ -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<NodeBindingsMac*>(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_);
index 6ae79c0a60b574228efd9de32ee02184083a418c..4929c1a2cf6d1bc2747aa07df0468e23031713a5 100644 (file)
@@ -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.