From d65edb7b2d228497056e18100c882f7cf7d59c36 Mon Sep 17 00:00:00 2001 From: rvargas Date: Tue, 31 Mar 2015 21:02:51 -0700 Subject: Base: Truncate the timeout of WaitableEvent::TimedWait on Windows. The timeout has to be adjusted to milliseconds (the resolution of the underlying call), but it should be truncated instead of extended, because the documentation clearly states that the function can fail in less time than the passed-in timeout, and by definition, the timeout is the maximum time that the caller is willing to block. BUG=none Review URL: https://codereview.chromium.org/1040833002 Cr-Commit-Position: refs/heads/master@{#323178} --- base/synchronization/waitable_event_win.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'base/synchronization') diff --git a/base/synchronization/waitable_event_win.cc b/base/synchronization/waitable_event_win.cc index 6bec4b4..4db5627 100644 --- a/base/synchronization/waitable_event_win.cc +++ b/base/synchronization/waitable_event_win.cc @@ -51,10 +51,10 @@ void WaitableEvent::Wait() { bool WaitableEvent::TimedWait(const TimeDelta& max_time) { base::ThreadRestrictions::AssertWaitAllowed(); DCHECK_GE(max_time, TimeDelta()); - // Be careful here. TimeDelta has a precision of microseconds, but this API - // is in milliseconds. If there are 5.5ms left, should the delay be 5 or 6? - // It should be 6 to avoid returning too early. - DWORD timeout = saturated_cast(max_time.InMillisecondsRoundedUp()); + // Truncate the timeout to milliseconds. The API specifies that this method + // can return in less than |max_time| (when returning false), as the argument + // is the maximum time that a caller is willing to wait. + DWORD timeout = saturated_cast(max_time.InMilliseconds()); DWORD result = WaitForSingleObject(handle_.Get(), timeout); switch (result) { -- cgit v1.1