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

Side by Side Diff: base/synchronization/waitable_event_win.cc

Issue 1040833002: Base: Truncate the timeout of WaitableEvent::TimedWait on Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/synchronization/waitable_event.h" 5 #include "base/synchronization/waitable_event.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/numerics/safe_conversions.h" 10 #include "base/numerics/safe_conversions.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 base::ThreadRestrictions::AssertWaitAllowed(); 44 base::ThreadRestrictions::AssertWaitAllowed();
45 DWORD result = WaitForSingleObject(handle_.Get(), INFINITE); 45 DWORD result = WaitForSingleObject(handle_.Get(), INFINITE);
46 // It is most unexpected that this should ever fail. Help consumers learn 46 // It is most unexpected that this should ever fail. Help consumers learn
47 // about it if it should ever fail. 47 // about it if it should ever fail.
48 DCHECK_EQ(WAIT_OBJECT_0, result) << "WaitForSingleObject failed"; 48 DCHECK_EQ(WAIT_OBJECT_0, result) << "WaitForSingleObject failed";
49 } 49 }
50 50
51 bool WaitableEvent::TimedWait(const TimeDelta& max_time) { 51 bool WaitableEvent::TimedWait(const TimeDelta& max_time) {
52 base::ThreadRestrictions::AssertWaitAllowed(); 52 base::ThreadRestrictions::AssertWaitAllowed();
53 DCHECK_GE(max_time, TimeDelta()); 53 DCHECK_GE(max_time, TimeDelta());
54 // Be careful here. TimeDelta has a precision of microseconds, but this API 54 // Truncate the timeout to milliseconds. The API specifies that this method
55 // is in milliseconds. If there are 5.5ms left, should the delay be 5 or 6? 55 // can return in less than |max_time| (when returning false), as the argument
56 // It should be 6 to avoid returning too early. 56 // is the maximum time that a caller is willing to wait.
57 DWORD timeout = saturated_cast<DWORD>(max_time.InMillisecondsRoundedUp()); 57 DWORD timeout = saturated_cast<DWORD>(max_time.InMilliseconds());
58 58
59 DWORD result = WaitForSingleObject(handle_.Get(), timeout); 59 DWORD result = WaitForSingleObject(handle_.Get(), timeout);
60 switch (result) { 60 switch (result) {
61 case WAIT_OBJECT_0: 61 case WAIT_OBJECT_0:
62 return true; 62 return true;
63 case WAIT_TIMEOUT: 63 case WAIT_TIMEOUT:
64 return false; 64 return false;
65 } 65 }
66 // It is most unexpected that this should ever fail. Help consumers learn 66 // It is most unexpected that this should ever fail. Help consumers learn
67 // about it if it should ever fail. 67 // about it if it should ever fail.
(...skipping 19 matching lines...) Expand all
87 INFINITE); // no timeout 87 INFINITE); // no timeout
88 if (result >= WAIT_OBJECT_0 + count) { 88 if (result >= WAIT_OBJECT_0 + count) {
89 DPLOG(FATAL) << "WaitForMultipleObjects failed"; 89 DPLOG(FATAL) << "WaitForMultipleObjects failed";
90 return 0; 90 return 0;
91 } 91 }
92 92
93 return result - WAIT_OBJECT_0; 93 return result - WAIT_OBJECT_0;
94 } 94 }
95 95
96 } // namespace base 96 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698