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_watcher.h" | 5 #include "base/synchronization/waitable_event_watcher.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/synchronization/waitable_event.h" | 8 #include "base/synchronization/waitable_event.h" |
9 #include "base/win/object_watcher.h" | 9 #include "base/win/object_watcher.h" |
10 | 10 |
11 namespace base { | 11 namespace base { |
12 | 12 |
13 WaitableEventWatcher::WaitableEventWatcher() | 13 WaitableEventWatcher::WaitableEventWatcher() = default; |
14 : event_(NULL) { | |
15 } | |
16 | 14 |
17 WaitableEventWatcher::~WaitableEventWatcher() { | 15 WaitableEventWatcher::~WaitableEventWatcher() { |
18 } | 16 } |
19 | 17 |
20 bool WaitableEventWatcher::StartWatching( | 18 bool WaitableEventWatcher::StartWatching( |
21 WaitableEvent* event, | 19 WaitableEvent* event, |
22 const EventCallback& callback) { | 20 const EventCallback& callback) { |
23 callback_ = callback; | 21 callback_ = callback; |
24 event_ = event; | 22 event_ = event; |
25 return watcher_.StartWatchingOnce(event->handle(), this); | 23 return watcher_.StartWatchingOnce(event->handle(), this); |
26 } | 24 } |
27 | 25 |
28 void WaitableEventWatcher::StopWatching() { | 26 void WaitableEventWatcher::StopWatching() { |
29 callback_.Reset(); | 27 callback_.Reset(); |
30 event_ = NULL; | 28 event_ = NULL; |
31 watcher_.StopWatching(); | 29 watcher_.StopWatching(); |
32 } | 30 } |
33 | 31 |
34 WaitableEvent* WaitableEventWatcher::GetWatchedEvent() { | |
35 return event_; | |
36 } | |
37 | |
38 void WaitableEventWatcher::OnObjectSignaled(HANDLE h) { | 32 void WaitableEventWatcher::OnObjectSignaled(HANDLE h) { |
39 WaitableEvent* event = event_; | 33 WaitableEvent* event = event_; |
40 EventCallback callback = callback_; | 34 EventCallback callback = callback_; |
41 event_ = NULL; | 35 event_ = NULL; |
42 callback_.Reset(); | 36 callback_.Reset(); |
43 DCHECK(event); | 37 DCHECK(event); |
44 | 38 |
45 callback.Run(event); | 39 callback.Run(event); |
46 } | 40 } |
47 | 41 |
48 } // namespace base | 42 } // namespace base |
OLD | NEW |