blob: 6533539d14db8b4cc35e7348d82e78c724998b32 [file] [log] [blame]
[email protected]44f9c952011-01-02 06:05:391// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]1c4947f2009-01-15 22:25:112// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]44f9c952011-01-02 06:05:395#include "base/synchronization/waitable_event_watcher.h"
[email protected]1c4947f2009-01-15 22:25:116
7#include "base/compiler_specific.h"
[email protected]44f9c952011-01-02 06:05:398#include "base/synchronization/waitable_event.h"
[email protected]a8d1ebbe2011-01-01 18:26:169#include "base/win/object_watcher.h"
[email protected]1c4947f2009-01-15 22:25:1110
11namespace base {
12
[email protected]1c4947f2009-01-15 22:25:1113WaitableEventWatcher::WaitableEventWatcher()
[email protected]329be052013-02-04 18:14:2814 : event_(NULL) {
[email protected]1c4947f2009-01-15 22:25:1115}
16
17WaitableEventWatcher::~WaitableEventWatcher() {
18}
19
[email protected]329be052013-02-04 18:14:2820bool WaitableEventWatcher::StartWatching(
21 WaitableEvent* event,
22 const EventCallback& callback) {
23 callback_ = callback;
[email protected]1c4947f2009-01-15 22:25:1124 event_ = event;
jam7fab1082015-09-29 02:26:1825 return watcher_.StartWatchingOnce(event->handle(), this);
[email protected]1c4947f2009-01-15 22:25:1126}
27
28void WaitableEventWatcher::StopWatching() {
[email protected]329be052013-02-04 18:14:2829 callback_.Reset();
[email protected]1c4947f2009-01-15 22:25:1130 event_ = NULL;
31 watcher_.StopWatching();
32}
33
34WaitableEvent* WaitableEventWatcher::GetWatchedEvent() {
35 return event_;
36}
37
[email protected]329be052013-02-04 18:14:2838void WaitableEventWatcher::OnObjectSignaled(HANDLE h) {
[email protected]1c4947f2009-01-15 22:25:1139 WaitableEvent* event = event_;
[email protected]329be052013-02-04 18:14:2840 EventCallback callback = callback_;
[email protected]1c4947f2009-01-15 22:25:1141 event_ = NULL;
[email protected]329be052013-02-04 18:14:2842 callback_.Reset();
[email protected]1c4947f2009-01-15 22:25:1143 DCHECK(event);
44
[email protected]329be052013-02-04 18:14:2845 callback.Run(event);
[email protected]1c4947f2009-01-15 22:25:1146}
47
48} // namespace base