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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 } | 68 } |
69 // It is most unexpected that this should ever fail. Help consumers learn | 69 // It is most unexpected that this should ever fail. Help consumers learn |
70 // about it if it should ever fail. | 70 // about it if it should ever fail. |
71 NOTREACHED() << "WaitForSingleObject failed"; | 71 NOTREACHED() << "WaitForSingleObject failed"; |
72 return false; | 72 return false; |
73 } | 73 } |
74 | 74 |
75 // static | 75 // static |
76 size_t WaitableEvent::WaitMany(WaitableEvent** events, size_t count) { | 76 size_t WaitableEvent::WaitMany(WaitableEvent** events, size_t count) { |
77 HANDLE handles[MAXIMUM_WAIT_OBJECTS]; | 77 HANDLE handles[MAXIMUM_WAIT_OBJECTS]; |
78 CHECK_LE(count, MAXIMUM_WAIT_OBJECTS) | 78 DCHECK_LE(count, MAXIMUM_WAIT_OBJECTS) |
jar (doing other things)
2011/10/23 00:36:28
This protects us from a buffer overrun if we could
| |
79 << "Can only wait on " << MAXIMUM_WAIT_OBJECTS << " with WaitMany"; | 79 << "Can only wait on " << MAXIMUM_WAIT_OBJECTS << " with WaitMany"; |
80 | 80 |
81 for (size_t i = 0; i < count; ++i) | 81 for (size_t i = 0; i < count; ++i) |
82 handles[i] = events[i]->handle(); | 82 handles[i] = events[i]->handle(); |
83 | 83 |
84 // The cast is safe because count is small - see the CHECK above. | 84 // The cast is safe because count is small - see the CHECK above. |
85 DWORD result = | 85 DWORD result = |
86 WaitForMultipleObjects(static_cast<DWORD>(count), | 86 WaitForMultipleObjects(static_cast<DWORD>(count), |
87 handles, | 87 handles, |
88 FALSE, // don't wait for all the objects | 88 FALSE, // don't wait for all the objects |
89 INFINITE); // no timeout | 89 INFINITE); // no timeout |
90 if (result >= WAIT_OBJECT_0 + count) { | 90 if (result >= WAIT_OBJECT_0 + count) { |
91 NOTREACHED() << "WaitForMultipleObjects failed: " << GetLastError(); | 91 NOTREACHED() << "WaitForMultipleObjects failed: " << GetLastError(); |
92 return 0; | 92 return 0; |
93 } | 93 } |
94 | 94 |
95 return result - WAIT_OBJECT_0; | 95 return result - WAIT_OBJECT_0; |
96 } | 96 } |
97 | 97 |
98 } // namespace base | 98 } // namespace base |
OLD | NEW |