Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(129)

Unified Diff: base/synchronization/waitable_event_win.cc

Issue 999753005: Make sure that WaitableEvent::TimedWait works fine with large timeouts. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/synchronization/waitable_event_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/synchronization/waitable_event_win.cc
diff --git a/base/synchronization/waitable_event_win.cc b/base/synchronization/waitable_event_win.cc
index 770c582aedeaf1975ec166efcf1fc94a9b8355ea..6bec4b423360fd258f52d5fec56ce9ef7fe067c5 100644
--- a/base/synchronization/waitable_event_win.cc
+++ b/base/synchronization/waitable_event_win.cc
@@ -4,10 +4,10 @@
#include "base/synchronization/waitable_event.h"
-#include <math.h>
#include <windows.h>
#include "base/logging.h"
+#include "base/numerics/safe_conversions.h"
#include "base/threading/thread_restrictions.h"
#include "base/time/time.h"
@@ -37,7 +37,7 @@ void WaitableEvent::Signal() {
}
bool WaitableEvent::IsSignaled() {
- return TimedWait(TimeDelta::FromMilliseconds(0));
+ return TimedWait(TimeDelta());
}
void WaitableEvent::Wait() {
@@ -50,13 +50,13 @@ void WaitableEvent::Wait() {
bool WaitableEvent::TimedWait(const TimeDelta& max_time) {
base::ThreadRestrictions::AssertWaitAllowed();
- DCHECK(max_time >= TimeDelta::FromMicroseconds(0));
+ 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.
- double timeout = ceil(max_time.InMillisecondsF());
- DWORD result = WaitForSingleObject(handle_.Get(),
- static_cast<DWORD>(timeout));
+ DWORD timeout = saturated_cast<DWORD>(max_time.InMillisecondsRoundedUp());
+
+ DWORD result = WaitForSingleObject(handle_.Get(), timeout);
switch (result) {
case WAIT_OBJECT_0:
return true;
« no previous file with comments | « base/synchronization/waitable_event_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698