Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(249)

Side by Side Diff: base/synchronization/waitable_event_watcher_win.cc

Issue 2801593002: Convert WaitableEvent::EventCallback to OnceCallback (Closed)
Patch Set: +#include <utility> Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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() = default; 13 WaitableEventWatcher::WaitableEventWatcher() = default;
14 14
15 WaitableEventWatcher::~WaitableEventWatcher() { 15 WaitableEventWatcher::~WaitableEventWatcher() {
16 } 16 }
17 17
18 bool WaitableEventWatcher::StartWatching( 18 bool WaitableEventWatcher::StartWatching(WaitableEvent* event,
19 WaitableEvent* event, 19 EventCallback callback) {
20 const EventCallback& callback) { 20 callback_ = std::move(callback);
21 callback_ = callback;
22 event_ = event; 21 event_ = event;
23 return watcher_.StartWatchingOnce(event->handle(), this); 22 return watcher_.StartWatchingOnce(event->handle(), this);
24 } 23 }
25 24
26 void WaitableEventWatcher::StopWatching() { 25 void WaitableEventWatcher::StopWatching() {
27 callback_.Reset(); 26 callback_.Reset();
28 event_ = NULL; 27 event_ = NULL;
29 watcher_.StopWatching(); 28 watcher_.StopWatching();
30 } 29 }
31 30
32 void WaitableEventWatcher::OnObjectSignaled(HANDLE h) { 31 void WaitableEventWatcher::OnObjectSignaled(HANDLE h) {
33 WaitableEvent* event = event_; 32 WaitableEvent* event = event_;
34 EventCallback callback = callback_; 33 EventCallback callback = std::move(callback_);
35 event_ = NULL; 34 event_ = NULL;
36 callback_.Reset();
37 DCHECK(event); 35 DCHECK(event);
38 36
39 callback.Run(event); 37 std::move(callback).Run(event);
40 } 38 }
41 39
42 } // namespace base 40 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698