OLD | NEW |
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 <math.h> | 7 #include <math.h> |
8 #include <windows.h> | 8 #include <windows.h> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 } | 39 } |
40 | 40 |
41 void WaitableEvent::Signal() { | 41 void WaitableEvent::Signal() { |
42 SetEvent(handle_); | 42 SetEvent(handle_); |
43 } | 43 } |
44 | 44 |
45 bool WaitableEvent::IsSignaled() { | 45 bool WaitableEvent::IsSignaled() { |
46 return TimedWait(TimeDelta::FromMilliseconds(0)); | 46 return TimedWait(TimeDelta::FromMilliseconds(0)); |
47 } | 47 } |
48 | 48 |
49 bool WaitableEvent::Wait() { | 49 void WaitableEvent::Wait() { |
50 DWORD result = WaitForSingleObject(handle_, INFINITE); | 50 DWORD result = WaitForSingleObject(handle_, INFINITE); |
51 // It is most unexpected that this should ever fail. Help consumers learn | 51 // It is most unexpected that this should ever fail. Help consumers learn |
52 // about it if it should ever fail. | 52 // about it if it should ever fail. |
53 DCHECK_EQ(WAIT_OBJECT_0, result) << "WaitForSingleObject failed"; | 53 DCHECK_EQ(WAIT_OBJECT_0, result) << "WaitForSingleObject failed"; |
54 return result == WAIT_OBJECT_0; | |
55 } | 54 } |
56 | 55 |
57 bool WaitableEvent::TimedWait(const TimeDelta& max_time) { | 56 bool WaitableEvent::TimedWait(const TimeDelta& max_time) { |
58 DCHECK(max_time >= TimeDelta::FromMicroseconds(0)); | 57 DCHECK(max_time >= TimeDelta::FromMicroseconds(0)); |
59 // Be careful here. TimeDelta has a precision of microseconds, but this API | 58 // Be careful here. TimeDelta has a precision of microseconds, but this API |
60 // is in milliseconds. If there are 5.5ms left, should the delay be 5 or 6? | 59 // is in milliseconds. If there are 5.5ms left, should the delay be 5 or 6? |
61 // It should be 6 to avoid returning too early. | 60 // It should be 6 to avoid returning too early. |
62 double timeout = ceil(max_time.InMillisecondsF()); | 61 double timeout = ceil(max_time.InMillisecondsF()); |
63 DWORD result = WaitForSingleObject(handle_, static_cast<DWORD>(timeout)); | 62 DWORD result = WaitForSingleObject(handle_, static_cast<DWORD>(timeout)); |
64 switch (result) { | 63 switch (result) { |
(...skipping 25 matching lines...) Expand all Loading... |
90 INFINITE); // no timeout | 89 INFINITE); // no timeout |
91 if (result >= WAIT_OBJECT_0 + count) { | 90 if (result >= WAIT_OBJECT_0 + count) { |
92 NOTREACHED() << "WaitForMultipleObjects failed: " << GetLastError(); | 91 NOTREACHED() << "WaitForMultipleObjects failed: " << GetLastError(); |
93 return 0; | 92 return 0; |
94 } | 93 } |
95 | 94 |
96 return result - WAIT_OBJECT_0; | 95 return result - WAIT_OBJECT_0; |
97 } | 96 } |
98 | 97 |
99 } // namespace base | 98 } // namespace base |
OLD | NEW |