Browse Source

Revert "Simplify next tick logic by looping around ev_loop"

This reverts commit 241ea7e595.

Fixes GH-511: https://github.com/ry/node/issues/issue/511
v0.7.4-release
Ryan Dahl 14 years ago
parent
commit
d0beac70f4
  1. 6
      deps/libev/ev.c
  2. 1
      deps/libev/ev.h
  3. 34
      src/node.cc

6
deps/libev/ev.c

@ -2469,12 +2469,6 @@ ev_unref (EV_P)
--activecnt;
}
int
ev_activecnt (EV_P)
{
return activecnt;
}
void
ev_now_update (EV_P)
{

1
deps/libev/ev.h

@ -603,7 +603,6 @@ void ev_break (EV_P_ int how); /* set to 1 to break out of event loop, set to 2
*/
void ev_ref (EV_P);
void ev_unref (EV_P);
int ev_activecnt (EV_P);
/*
* convenience function, wait for a single event, without registering an event watcher

34
src/node.cc

@ -83,6 +83,7 @@ static int max_stack_size = 0;
static ev_check check_tick_watcher;
static ev_prepare prepare_tick_watcher;
static ev_idle tick_spinner;
static bool need_tick_cb;
static Persistent<String> tick_callback_sym;
@ -172,15 +173,28 @@ static void Check(EV_P_ ev_check *watcher, int revents) {
static Handle<Value> NeedTickCallback(const Arguments& args) {
HandleScope scope;
need_tick_cb = true;
// TODO: this tick_spinner shouldn't be necessary. An ev_prepare should be
// sufficent, the problem is only in the case of the very last "tick" -
// 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.
ev_idle_start(EV_DEFAULT_UC_ &tick_spinner);
return Undefined();
}
static void Spin(EV_P_ ev_idle *watcher, int revents) {
assert(watcher == &tick_spinner);
assert(revents == EV_IDLE);
}
static void Tick(void) {
// Avoid entering a V8 scope.
if (!need_tick_cb) return;
need_tick_cb = false;
ev_idle_stop(EV_DEFAULT_UC_ &tick_spinner);
HandleScope scope;
@ -1920,6 +1934,8 @@ int Start(int argc, char *argv[]) {
ev_check_start(EV_DEFAULT_UC_ &node::check_tick_watcher);
ev_unref(EV_DEFAULT_UC);
ev_idle_init(&node::tick_spinner, node::Spin);
ev_check_init(&node::gc_check, node::Check);
ev_check_start(EV_DEFAULT_UC_ &node::gc_check);
ev_unref(EV_DEFAULT_UC);
@ -1998,18 +2014,12 @@ int Start(int argc, char *argv[]) {
// Avoids failing on test/simple/test-eio-race3.js though
ev_idle_start(EV_DEFAULT_UC_ &eio_poller);
do {
// 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
// ev_unref'd) then this function exits. As long as there are active
// watchers, it blocks.
ev_loop(EV_DEFAULT_UC_ 0);
Tick();
} while (need_tick_cb || ev_activecnt(EV_DEFAULT_UC) > 0);
// 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
// ev_unref'd) then this function exits. As long as there are active
// watchers, it blocks.
ev_loop(EV_DEFAULT_UC_ 0);
// process.emit('exit')

Loading…
Cancel
Save