From ef85bdaffbc878b44b24f01e97f7c7e7301c6dfe Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Fri, 12 Apr 2013 19:37:52 +0200 Subject: [PATCH 1/3] unix: silence STATIC_ASSERT compiler warnings Newer versions of gcc complain about the definition of the zero element array. Squelch that warning by turning it into a one element array. --- src/unix/internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/unix/internal.h b/src/unix/internal.h index 899c972b..61cb1ec1 100644 --- a/src/unix/internal.h +++ b/src/unix/internal.h @@ -46,7 +46,7 @@ #endif #define STATIC_ASSERT(expr) \ - void uv__static_assert(int static_assert_failed[0 - !(expr)]) + void uv__static_assert(int static_assert_failed[1 - 2 * !(expr)]) #define ACCESS_ONCE(type, var) \ (*(volatile type*) &(var)) From 09ff5100e3ecae807dd19796e08a0b756bc04ddd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Tue, 16 Apr 2013 16:29:48 +0200 Subject: [PATCH 2/3] windows: make timers handle large timeouts Fixes a bug where timers with very large timeouts run on the next tick. Based on a similar bug fix for unix (9b61939). Fixes joyent/node#5101. --- src/win/timer.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/win/timer.c b/src/win/timer.c index 0c055da9..7fd10571 100644 --- a/src/win/timer.c +++ b/src/win/timer.c @@ -87,6 +87,17 @@ void uv_timer_endgame(uv_loop_t* loop, uv_timer_t* handle) { } +static uint64_t get_clamped_due_time(uint64_t loop_time, uint64_t timeout) { + uint64_t clamped_timeout; + + clamped_timeout = loop_time + timeout; + if (clamped_timeout < timeout) + clamped_timeout = (uint64_t) -1; + + return clamped_timeout; +} + + int uv_timer_start(uv_timer_t* handle, uv_timer_cb timer_cb, uint64_t timeout, uint64_t repeat) { uv_loop_t* loop = handle->loop; @@ -97,7 +108,7 @@ int uv_timer_start(uv_timer_t* handle, uv_timer_cb timer_cb, uint64_t timeout, } handle->timer_cb = timer_cb; - handle->due = loop->time + timeout; + handle->due = get_clamped_due_time(loop->time, timeout); handle->repeat = repeat; handle->flags |= UV_HANDLE_ACTIVE; uv__handle_start(handle); @@ -143,7 +154,7 @@ int uv_timer_again(uv_timer_t* handle) { } if (handle->repeat) { - handle->due = loop->time + handle->repeat; + handle->due = get_clamped_due_time(loop->time, handle->repeat); if (RB_INSERT(uv_timer_tree_s, &loop->timers, handle) != NULL) { uv_fatal_error(ERROR_INVALID_DATA, "RB_INSERT"); @@ -212,7 +223,7 @@ void uv_process_timers(uv_loop_t* loop) { if (timer->repeat != 0) { /* If it is a repeating timer, reschedule with repeat timeout. */ - timer->due += timer->repeat; + timer->due = get_clamped_due_time(timer->due, timer->repeat); if (timer->due < loop->time) { timer->due = loop->time; } From a3963883b81ec2c2612511ff3fa885b2944d8457 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Thu, 18 Apr 2013 02:55:15 +0200 Subject: [PATCH 3/3] windows: remove superfluous assert statement --- src/win/core.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/win/core.c b/src/win/core.c index 9680c7e5..62d6bf8f 100644 --- a/src/win/core.c +++ b/src/win/core.c @@ -205,9 +205,7 @@ static void uv_poll(uv_loop_t* loop, int block) { if (overlapped) { /* Package was dequeued */ req = uv_overlapped_to_req(overlapped); - uv_insert_pending_req(loop, req); - } else if (GetLastError() != WAIT_TIMEOUT) { /* Serious error */ uv_fatal_error(GetLastError(), "GetQueuedCompletionStatus"); @@ -229,14 +227,13 @@ static void uv_poll_ex(uv_loop_t* loop, int block) { timeout = 0; } - assert(pGetQueuedCompletionStatusEx); - success = pGetQueuedCompletionStatusEx(loop->iocp, overlappeds, ARRAY_SIZE(overlappeds), &count, timeout, FALSE); + if (success) { for (i = 0; i < count; i++) { /* Package was dequeued */