Move the watcher queue hack to NodeBindingsMac.

It's mac only.
This commit is contained in:
Cheng Zhao 2013-07-23 13:08:40 +08:00
parent 620c9fa109
commit 9efde9577a
4 changed files with 29 additions and 18 deletions

View file

@ -134,10 +134,6 @@ void NodeBindings::RunMessageLoop() {
// The MessageLoop should have been created, remember the one in main thread. // The MessageLoop should have been created, remember the one in main thread.
message_loop_ = base::MessageLoop::current(); 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. // Run uv loop for once to give the uv__io_poll a chance to add all events.
UvRunOnce(); UvRunOnce();
} }
@ -164,6 +160,10 @@ void NodeBindings::WakeupMainThread() {
base::Unretained(this))); base::Unretained(this)));
} }
void NodeBindings::WakeupEmbedThread() {
uv_async_send(&dummy_uv_handle_);
}
// static // static
void NodeBindings::EmbedThreadRunner(void *arg) { void NodeBindings::EmbedThreadRunner(void *arg) {
NodeBindings* self = static_cast<NodeBindings*>(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 } // namespace atom

View file

@ -51,6 +51,9 @@ class NodeBindings {
// Make the main thread run libuv loop. // Make the main thread run libuv loop.
void WakeupMainThread(); void WakeupMainThread();
// Interrupt the PollEvents.
void WakeupEmbedThread();
// Are we running in browser. // Are we running in browser.
bool is_browser_; bool is_browser_;
@ -64,9 +67,6 @@ class NodeBindings {
// Thread to poll uv events. // Thread to poll uv events.
static void EmbedThreadRunner(void *arg); 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. // Whether the libuv loop has ended.
bool embed_closed_; bool embed_closed_;

View file

@ -27,6 +27,23 @@ NodeBindingsMac::NodeBindingsMac(bool is_browser)
NodeBindingsMac::~NodeBindingsMac() { 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() { void NodeBindingsMac::PollEvents() {
struct timespec spec; struct timespec spec;
int timeout = uv_backend_timeout(uv_loop_); int timeout = uv_backend_timeout(uv_loop_);

View file

@ -15,7 +15,12 @@ class NodeBindingsMac : public NodeBindings {
explicit NodeBindingsMac(bool is_browser); explicit NodeBindingsMac(bool is_browser);
virtual ~NodeBindingsMac(); virtual ~NodeBindingsMac();
virtual void RunMessageLoop() OVERRIDE;
private: private:
// Called when uv's watcher queue changes.
static void OnWatcherQueueChanged(uv_loop_t* loop);
virtual void PollEvents() OVERRIDE; virtual void PollEvents() OVERRIDE;
// Kqueue to poll for uv's backend fd. // Kqueue to poll for uv's backend fd.