@@ -83,7 +83,6 @@ static int max_stack_size = 0;
8383
8484static ev_check check_tick_watcher;
8585static ev_prepare prepare_tick_watcher;
86- static ev_idle tick_spinner;
8786static bool need_tick_cb;
8887static Persistent<String> tick_callback_sym;
8988
@@ -173,28 +172,15 @@ static void Check(EV_P_ ev_check *watcher, int revents) {
173172static Handle<Value> NeedTickCallback (const Arguments& args) {
174173 HandleScope scope;
175174 need_tick_cb = true ;
176- // TODO: this tick_spinner shouldn't be necessary. An ev_prepare should be
177- // sufficent, the problem is only in the case of the very last "tick" -
178- // there is nothing left to do in the event loop and libev will exit. The
179- // ev_prepare callback isn't called before exiting. Thus we start this
180- // tick_spinner to keep the event loop alive long enough to handle it.
181- ev_idle_start (EV_DEFAULT_UC_ &tick_spinner);
182175 return Undefined ();
183176}
184177
185178
186- static void Spin (EV_P_ ev_idle *watcher, int revents) {
187- assert (watcher == &tick_spinner);
188- assert (revents == EV_IDLE);
189- }
190-
191-
192179static void Tick (void ) {
193180 // Avoid entering a V8 scope.
194181 if (!need_tick_cb) return ;
195182
196183 need_tick_cb = false ;
197- ev_idle_stop (EV_DEFAULT_UC_ &tick_spinner);
198184
199185 HandleScope scope;
200186
@@ -1892,8 +1878,6 @@ int Start(int argc, char *argv[]) {
18921878 ev_check_start (EV_DEFAULT_UC_ &node::check_tick_watcher);
18931879 ev_unref (EV_DEFAULT_UC);
18941880
1895- ev_idle_init (&node::tick_spinner, node::Spin);
1896-
18971881 ev_check_init (&node::gc_check, node::Check);
18981882 ev_check_start (EV_DEFAULT_UC_ &node::gc_check);
18991883 ev_unref (EV_DEFAULT_UC);
@@ -1972,12 +1956,18 @@ int Start(int argc, char *argv[]) {
19721956 // Avoids failing on test/simple/test-eio-race3.js though
19731957 ev_idle_start (EV_DEFAULT_UC_ &eio_poller);
19741958
1975- // All our arguments are loaded. We've evaluated all of the scripts. We
1976- // might even have created TCP servers. Now we enter the main eventloop. If
1977- // there are no watchers on the loop (except for the ones that were
1978- // ev_unref'd) then this function exits. As long as there are active
1979- // watchers, it blocks.
1980- ev_loop (EV_DEFAULT_UC_ 0 );
1959+
1960+ do {
1961+ // All our arguments are loaded. We've evaluated all of the scripts. We
1962+ // might even have created TCP servers. Now we enter the main eventloop. If
1963+ // there are no watchers on the loop (except for the ones that were
1964+ // ev_unref'd) then this function exits. As long as there are active
1965+ // watchers, it blocks.
1966+ ev_loop (EV_DEFAULT_UC_ 0 );
1967+
1968+ Tick ();
1969+
1970+ } while (need_tick_cb || ev_activecnt (EV_DEFAULT_UC) > 0 );
19811971
19821972
19831973 // process.emit('exit')
0 commit comments