Browse Source

Simplify next tick logic by looping around ev_loop

This is also in preparation for the writev patch, which needs to dump
remaining data after ev_loop ends.
v0.7.4-release
Ryan Dahl 14 years ago
parent
commit
241ea7e595
  1. 6
      deps/libev/ev.c
  2. 1
      deps/libev/ev.h
  3. 34
      src/node.cc

6
deps/libev/ev.c

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

1
deps/libev/ev.h

@ -603,6 +603,7 @@ 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,7 +83,6 @@ 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;
@ -173,28 +172,15 @@ 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;
@ -1892,8 +1878,6 @@ 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);
@ -1972,12 +1956,18 @@ int Start(int argc, char *argv[]) {
// 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
// ev_unref'd) then this function exits. As long as there are active
// watchers, it blocks.
ev_loop(EV_DEFAULT_UC_ 0);
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);
// process.emit('exit')

Loading…
Cancel
Save