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> |
11 | 11 |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/numerics/safe_conversions.h" | 13 #include "base/numerics/safe_conversions.h" |
14 #include "base/threading/thread_restrictions.h" | 14 #include "base/threading/thread_restrictions.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
16 | 16 |
17 namespace base { | 17 namespace base { |
18 | 18 |
19 WaitableEvent::WaitableEvent(ResetPolicy reset_policy, | 19 WaitableEvent::WaitableEvent(ResetPolicy reset_policy, |
20 InitialState initial_state) | 20 InitialState initial_state) |
21 : WaitableEvent(reset_policy == ResetPolicy::MANUAL, | 21 : handle_(CreateEvent(nullptr, |
22 initial_state == InitialState::SIGNALED) {} | 22 reset_policy == ResetPolicy::MANUAL, |
23 | 23 initial_state == InitialState::SIGNALED, |
24 WaitableEvent::WaitableEvent(bool manual_reset, bool signaled) | 24 nullptr)) { |
25 : handle_(CreateEvent(NULL, manual_reset, signaled, NULL)) { | |
26 // We're probably going to crash anyways if this is ever NULL, so we might as | 25 // We're probably going to crash anyways if this is ever NULL, so we might as |
27 // well make our stack reports more informative by crashing here. | 26 // well make our stack reports more informative by crashing here. |
28 CHECK(handle_.IsValid()); | 27 CHECK(handle_.IsValid()); |
29 } | 28 } |
30 | 29 |
31 WaitableEvent::WaitableEvent(win::ScopedHandle handle) | 30 WaitableEvent::WaitableEvent(win::ScopedHandle handle) |
32 : handle_(std::move(handle)) { | 31 : handle_(std::move(handle)) { |
33 CHECK(handle_.IsValid()) << "Tried to create WaitableEvent from NULL handle"; | 32 CHECK(handle_.IsValid()) << "Tried to create WaitableEvent from NULL handle"; |
34 } | 33 } |
35 | 34 |
36 WaitableEvent::~WaitableEvent() { | 35 WaitableEvent::~WaitableEvent() = default; |
37 } | |
38 | 36 |
39 void WaitableEvent::Reset() { | 37 void WaitableEvent::Reset() { |
40 ResetEvent(handle_.Get()); | 38 ResetEvent(handle_.Get()); |
41 } | 39 } |
42 | 40 |
43 void WaitableEvent::Signal() { | 41 void WaitableEvent::Signal() { |
44 SetEvent(handle_.Get()); | 42 SetEvent(handle_.Get()); |
45 } | 43 } |
46 | 44 |
47 bool WaitableEvent::IsSignaled() { | 45 bool WaitableEvent::IsSignaled() { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 INFINITE); // no timeout | 93 INFINITE); // no timeout |
96 if (result >= WAIT_OBJECT_0 + count) { | 94 if (result >= WAIT_OBJECT_0 + count) { |
97 DPLOG(FATAL) << "WaitForMultipleObjects failed"; | 95 DPLOG(FATAL) << "WaitForMultipleObjects failed"; |
98 return 0; | 96 return 0; |
99 } | 97 } |
100 | 98 |
101 return result - WAIT_OBJECT_0; | 99 return result - WAIT_OBJECT_0; |
102 } | 100 } |
103 | 101 |
104 } // namespace base | 102 } // namespace base |
OLD | NEW |