From 207901e7de1ceeb35b73a9aa4bc1f3bb9ab0ff2c Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Mon, 23 May 2011 15:38:54 -0700 Subject: [PATCH] Guard tick_spinner start/stop All tests passing on OSX. Thanks to Bert for debugging this. --- src/node.cc | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/node.cc b/src/node.cc index d47ea41af05..62765c2065d 100644 --- a/src/node.cc +++ b/src/node.cc @@ -216,8 +216,10 @@ static Handle NeedTickCallback(const Arguments& args) { // there is nothing left to do in the event loop and libev will exit. The // ev_prepare callback isn't called before exiting. Thus we start this // tick_spinner to keep the event loop alive long enough to handle it. - uv_idle_start(&tick_spinner, Spin); - uv_ref(); + if (!uv_is_active(&tick_spinner)) { + uv_idle_start(&tick_spinner, Spin); + uv_ref(); + } return Undefined(); } @@ -227,8 +229,10 @@ static void Tick(void) { if (!need_tick_cb) return; need_tick_cb = false; - uv_idle_stop(&tick_spinner); - uv_unref(); + if (uv_is_active(&tick_spinner)) { + uv_idle_stop(&tick_spinner); + uv_unref(); + } HandleScope scope; @@ -2369,9 +2373,12 @@ char** Init(int argc, char *argv[]) { ev_timer_init(&node::gc_timer, node::CheckStatus, 5., 5.); - // Setup the EIO thread pool - { // It requires 3, yes 3, watchers. + // Setup the EIO thread pool. It requires 3, yes 3, watchers. + { ev_idle_init(&node::eio_poller, node::DoPoll); + // TODO Probably don't need to start this each time. + // Avoids failing on test/simple/test-eio-race3.js though + ev_idle_start(EV_DEFAULT_UC_ &eio_poller); ev_async_init(&node::eio_want_poll_notifier, node::WantPollNotifier); ev_async_start(EV_DEFAULT_UC_ &node::eio_want_poll_notifier); @@ -2460,10 +2467,6 @@ int Start(int argc, char *argv[]) { // so your next reading stop should be node::Load()! Load(process); - // TODO Probably don't need to start this each time. - // Avoids failing on test/simple/test-eio-race3.js though - ev_idle_start(EV_DEFAULT_UC_ &eio_poller); - // All our arguments are loaded. We've evaluated all of the scripts. We // might even have created TCP servers. Now we enter the main eventloop. If // there are no watchers on the loop (except for the ones that were