From e628c7b37d2231ca0641201502ba5c7875a8d9fe Mon Sep 17 00:00:00 2001 From: Matt Mastracci Date: Thu, 20 Aug 2015 19:59:58 -0600 Subject: [PATCH] Fix for issue 1968: use uv_backend_timeout to determine timeout to match other platforms --- atom/common/node_bindings_win.cc | 45 ++++++++++++-------------------- 1 file changed, 17 insertions(+), 28 deletions(-) diff --git a/atom/common/node_bindings_win.cc b/atom/common/node_bindings_win.cc index b1ecaa570607..b8de4f59da3b 100644 --- a/atom/common/node_bindings_win.cc +++ b/atom/common/node_bindings_win.cc @@ -22,37 +22,26 @@ NodeBindingsWin::~NodeBindingsWin() { } void NodeBindingsWin::PollEvents() { - // Unlike Unix, in which we can just rely on one backend fd to determine - // whether we should iterate libuv loop, on Window, IOCP is just one part - // of the libuv loop, we should also check whether we have other types of - // events. - bool block = uv_loop_->idle_handles == NULL && - uv_loop_->pending_reqs_tail == NULL && - uv_loop_->endgame_handles == NULL && - !uv_loop_->stop_flag && - (uv_loop_->active_handles > 0 || - !QUEUE_EMPTY(&uv_loop_->active_reqs)); + // If there are other kinds of events pending, uv_backend_timeout will + // instruct us not to wait. + DWORD bytes, timeout; + ULONG_PTR key; + OVERLAPPED* overlapped; - // When there is no other types of events, we block on the IOCP. - if (block) { - DWORD bytes, timeout; - ULONG_PTR key; - OVERLAPPED* overlapped; + timeout = uv_backend_timeout(uv_loop_); - timeout = uv_backend_timeout(uv_loop_); - GetQueuedCompletionStatus(uv_loop_->iocp, - &bytes, - &key, - &overlapped, - timeout); + GetQueuedCompletionStatus(uv_loop_->iocp, + &bytes, + &key, + &overlapped, + timeout); - // Give the event back so libuv can deal with it. - if (overlapped != NULL) - PostQueuedCompletionStatus(uv_loop_->iocp, - bytes, - key, - overlapped); - } + // Give the event back so libuv can deal with it. + if (overlapped != NULL) + PostQueuedCompletionStatus(uv_loop_->iocp, + bytes, + key, + overlapped); } // static