Fix iOS build for XCode 4.6.
[chromium-blink-merge.git] / base / synchronization / waitable_event_watcher_win.cc
blob43e3c4700e3c5f65a39c6a28638ab39cc211d898
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
3 // found in the LICENSE file.
5 #include "base/synchronization/waitable_event_watcher.h"
7 #include "base/compiler_specific.h"
8 #include "base/synchronization/waitable_event.h"
9 #include "base/win/object_watcher.h"
11 namespace base {
13 WaitableEventWatcher::ObjectWatcherHelper::ObjectWatcherHelper(
14 WaitableEventWatcher* watcher)
15 : watcher_(watcher) {
18 void WaitableEventWatcher::ObjectWatcherHelper::OnObjectSignaled(HANDLE h) {
19 watcher_->OnObjectSignaled();
23 WaitableEventWatcher::WaitableEventWatcher()
24 : ALLOW_THIS_IN_INITIALIZER_LIST(helper_(this)),
25 event_(NULL),
26 delegate_(NULL) {
29 WaitableEventWatcher::~WaitableEventWatcher() {
32 bool WaitableEventWatcher::StartWatching(WaitableEvent* event,
33 Delegate* delegate) {
34 delegate_ = delegate;
35 event_ = event;
37 return watcher_.StartWatching(event->handle(), &helper_);
40 void WaitableEventWatcher::StopWatching() {
41 delegate_ = NULL;
42 event_ = NULL;
43 watcher_.StopWatching();
46 WaitableEvent* WaitableEventWatcher::GetWatchedEvent() {
47 return event_;
50 void WaitableEventWatcher::OnObjectSignaled() {
51 WaitableEvent* event = event_;
52 Delegate* delegate = delegate_;
53 event_ = NULL;
54 delegate_ = NULL;
55 DCHECK(event);
57 delegate->OnWaitableEventSignaled(event);
60 } // namespace base