int uv_run(uv_loop_t* loop, uv_run_mode mode) { int timeout; int r; r = uv__loop_alive(loop); if (!r) uv__update_time(loop); while (r != 0 && loop->stop_flag == 0) { UV_TICK_START(loop, mode); uv__update_time(loop); uv__run_timers(loop); uv__run_pending(loop); uv__run_idle(loop); uv__run_prepare(loop); timeout = 0; if ((mode & UV_RUN_NOWAIT) == 0) timeout = uv_backend_timeout(loop); uv__io_poll(loop, timeout); uv__run_check(loop); uv__run_closing_handles(loop); if (mode == UV_RUN_ONCE) { /* UV_RUN_ONCE implies forward progess: at least one callback must have * been invoked when it returns. uv__io_poll() can return without doing * I/O (meaning: no callbacks) when its timeout expires - which means we * have pending timers that satisfy the forward progress constraint. * * UV_RUN_NOWAIT makes no guarantees about progress so it's omitted from * the check. */ uv__update_time(loop); uv__run_timers(loop); } r = uv__loop_alive(loop); UV_TICK_STOP(loop, mode); if (mode & (UV_RUN_ONCE | UV_RUN_NOWAIT)) break; } /* The if statement lets gcc compile it to a conditional store. Avoids * dirtying a cache line. */ if (loop->stop_flag != 0) loop->stop_flag = 0; return r; }
int uv_run2(uv_loop_t* loop, uv_run_mode mode) { int r; if (!uv__loop_alive(loop)) return 0; do { uv__update_time(loop); uv__run_timers(loop); uv__run_idle(loop); uv__run_prepare(loop); uv__run_pending(loop); uv__io_poll(loop, (mode & UV_RUN_NOWAIT ? 0 : uv_backend_timeout(loop))); uv__run_check(loop); uv__run_closing_handles(loop); r = uv__loop_alive(loop); } while (r && !(mode & (UV_RUN_ONCE | UV_RUN_NOWAIT))); return r; }
int uv_run(uv_loop_t* loop, uv_run_mode mode) { int timeout; int r; r = uv__loop_alive(loop); while (r != 0 && loop->stop_flag == 0) { UV_TICK_START(loop, mode); uv__update_time(loop); uv__run_timers(loop); uv__run_idle(loop); uv__run_prepare(loop); uv__run_pending(loop); timeout = 0; if ((mode & UV_RUN_NOWAIT) == 0) timeout = uv_backend_timeout(loop); uv__io_poll(loop, timeout); uv__run_check(loop); uv__run_closing_handles(loop); r = uv__loop_alive(loop); UV_TICK_STOP(loop, mode); if (mode & (UV_RUN_ONCE | UV_RUN_NOWAIT)) break; } /* The if statement lets gcc compile it to a conditional store. Avoids * dirtying a cache line. */ if (loop->stop_flag != 0) loop->stop_flag = 0; return r; }