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 <windows.h> | 7 #include <windows.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <utility> | 10 #include <utility> |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 DWORD result = WaitForSingleObject(handle_.Get(), INFINITE); | 55 DWORD result = WaitForSingleObject(handle_.Get(), INFINITE); |
56 // It is most unexpected that this should ever fail. Help consumers learn | 56 // It is most unexpected that this should ever fail. Help consumers learn |
57 // about it if it should ever fail. | 57 // about it if it should ever fail. |
58 DCHECK_EQ(WAIT_OBJECT_0, result) << "WaitForSingleObject failed"; | 58 DCHECK_EQ(WAIT_OBJECT_0, result) << "WaitForSingleObject failed"; |
59 } | 59 } |
60 | 60 |
61 bool WaitableEvent::TimedWait(const TimeDelta& max_time) { | 61 bool WaitableEvent::TimedWait(const TimeDelta& max_time) { |
62 // Record the event that this thread is blocking upon (for hang diagnosis). | 62 // Record the event that this thread is blocking upon (for hang diagnosis). |
63 base::debug::ScopedEventWaitActivity event_activity(this); | 63 base::debug::ScopedEventWaitActivity event_activity(this); |
64 | 64 |
65 base::ThreadRestrictions::AssertWaitAllowed(); | |
66 DCHECK_GE(max_time, TimeDelta()); | 65 DCHECK_GE(max_time, TimeDelta()); |
| 66 if (!max_time.is_zero()) |
| 67 base::ThreadRestrictions::AssertWaitAllowed(); |
| 68 |
67 // Truncate the timeout to milliseconds. The API specifies that this method | 69 // Truncate the timeout to milliseconds. The API specifies that this method |
68 // can return in less than |max_time| (when returning false), as the argument | 70 // can return in less than |max_time| (when returning false), as the argument |
69 // is the maximum time that a caller is willing to wait. | 71 // is the maximum time that a caller is willing to wait. |
70 DWORD timeout = saturated_cast<DWORD>(max_time.InMilliseconds()); | 72 DWORD timeout = saturated_cast<DWORD>(max_time.InMilliseconds()); |
71 | 73 |
72 DWORD result = WaitForSingleObject(handle_.Get(), timeout); | 74 DWORD result = WaitForSingleObject(handle_.Get(), timeout); |
73 switch (result) { | 75 switch (result) { |
74 case WAIT_OBJECT_0: | 76 case WAIT_OBJECT_0: |
75 return true; | 77 return true; |
76 case WAIT_TIMEOUT: | 78 case WAIT_TIMEOUT: |
(...skipping 28 matching lines...) Expand all Loading... |
105 INFINITE); // no timeout | 107 INFINITE); // no timeout |
106 if (result >= WAIT_OBJECT_0 + count) { | 108 if (result >= WAIT_OBJECT_0 + count) { |
107 DPLOG(FATAL) << "WaitForMultipleObjects failed"; | 109 DPLOG(FATAL) << "WaitForMultipleObjects failed"; |
108 return 0; | 110 return 0; |
109 } | 111 } |
110 | 112 |
111 return result - WAIT_OBJECT_0; | 113 return result - WAIT_OBJECT_0; |
112 } | 114 } |
113 | 115 |
114 } // namespace base | 116 } // namespace base |
OLD | NEW |