ext/libuv/src/win/core.c in uvrb-0.1.4 vs ext/libuv/src/win/core.c in uvrb-0.2.0

- old
+ new

@@ -88,14 +88,15 @@ } /* To prevent uninitialized memory access, loop->time must be intialized */ /* to zero before calling uv_update_time for the first time. */ loop->time = 0; + loop->last_tick_count = 0; uv_update_time(loop); - ngx_queue_init(&loop->handle_queue); - ngx_queue_init(&loop->active_reqs); + QUEUE_INIT(&loop->handle_queue); + QUEUE_INIT(&loop->active_reqs); loop->active_handles = 0; loop->pending_reqs_tail = NULL; loop->endgame_handles = NULL; @@ -115,12 +116,10 @@ loop->active_tcp_streams = 0; loop->active_udp_streams = 0; loop->timer_counter = 0; loop->stop_flag = 0; - - loop->last_err = uv_ok_; } static void uv_default_loop_init(void) { /* Initialize libuv itself first */ @@ -207,10 +206,15 @@ req = uv_overlapped_to_req(overlapped); uv_insert_pending_req(loop, req); } else if (GetLastError() != WAIT_TIMEOUT) { /* Serious error */ uv_fatal_error(GetLastError(), "GetQueuedCompletionStatus"); + } else { + /* We're sure that at least `timeout` milliseconds have expired, but */ + /* this may not be reflected yet in the GetTickCount() return value. */ + /* Therefore we ensure it's taken into account here. */ + uv__time_forward(loop, timeout); } } static void uv_poll_ex(uv_loop_t* loop, int block) { @@ -241,17 +245,22 @@ uv_insert_pending_req(loop, req); } } else if (GetLastError() != WAIT_TIMEOUT) { /* Serious error */ uv_fatal_error(GetLastError(), "GetQueuedCompletionStatusEx"); + } else if (timeout > 0) { + /* We're sure that at least `timeout` milliseconds have expired, but */ + /* this may not be reflected yet in the GetTickCount() return value. */ + /* Therefore we ensure it's taken into account here. */ + uv__time_forward(loop, timeout); } } static int uv__loop_alive(uv_loop_t* loop) { return loop->active_handles > 0 || - !ngx_queue_empty(&loop->active_reqs) || + !QUEUE_EMPTY(&loop->active_reqs) || loop->endgame_handles != NULL; } int uv_run(uv_loop_t *loop, uv_run_mode mode) { @@ -269,29 +278,39 @@ r = uv__loop_alive(loop); while (r != 0 && loop->stop_flag == 0) { uv_update_time(loop); uv_process_timers(loop); - /* Call idle callbacks if nothing to do. */ - if (loop->pending_reqs_tail == NULL && - loop->endgame_handles == NULL) { - uv_idle_invoke(loop); - } - uv_process_reqs(loop); uv_process_endgames(loop); + uv_idle_invoke(loop); + uv_prepare_invoke(loop); (*poll)(loop, loop->idle_handles == NULL && loop->pending_reqs_tail == NULL && loop->endgame_handles == NULL && !loop->stop_flag && (loop->active_handles > 0 || - !ngx_queue_empty(&loop->active_reqs)) && + !QUEUE_EMPTY(&loop->active_reqs)) && !(mode & UV_RUN_NOWAIT)); uv_check_invoke(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_process_timers(loop); + } + r = uv__loop_alive(loop); if (mode & (UV_RUN_ONCE | UV_RUN_NOWAIT)) break; }