diff options
author | rvargas <rvargas@chromium.org> | 2015-03-31 21:02:51 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-04-01 04:03:41 +0000 |
commit | d65edb7b2d228497056e18100c882f7cf7d59c36 (patch) | |
tree | 2575aca1a24a6633da7e1de4f0f2586173b231b2 /base/synchronization | |
parent | 0bd2a738f107ad7021c70bfd36ae41e4565fe946 (diff) | |
download | chromium_src-d65edb7b2d228497056e18100c882f7cf7d59c36.zip chromium_src-d65edb7b2d228497056e18100c882f7cf7d59c36.tar.gz chromium_src-d65edb7b2d228497056e18100c882f7cf7d59c36.tar.bz2 |
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}
Diffstat (limited to 'base/synchronization')
-rw-r--r-- | base/synchronization/waitable_event_win.cc | 8 |
1 files changed, 4 insertions, 4 deletions
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<DWORD>(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<DWORD>(max_time.InMilliseconds()); DWORD result = WaitForSingleObject(handle_.Get(), timeout); switch (result) { |