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

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

Issue 10004001: Add virtual and OVERRIDE to base/ implementation files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Feedback from chromium-dev Created 8 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 | Annotate | Revision Log
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/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/synchronization/lock.h" 10 #include "base/synchronization/lock.h"
(...skipping 25 matching lines...) Expand all
36 AutoLock locked(lock_); 36 AutoLock locked(lock_);
37 flag_ = true; 37 flag_ = true;
38 } 38 }
39 39
40 bool value() const { 40 bool value() const {
41 AutoLock locked(lock_); 41 AutoLock locked(lock_);
42 return flag_; 42 return flag_;
43 } 43 }
44 44
45 private: 45 private:
46 friend class RefCountedThreadSafe<Flag>;
Nico 2012/04/05 19:16:02 likely unnecessary?
47 ~Flag() {}
Nico 2012/04/05 19:16:02 unnecessary, or at least unrelated?
Ryan Sleevi 2012/04/05 19:22:38 Unnecessary no, unrelated yes. This bled in from
48
46 mutable Lock lock_; 49 mutable Lock lock_;
47 bool flag_; 50 bool flag_;
48 }; 51 };
49 52
50 // ----------------------------------------------------------------------------- 53 // -----------------------------------------------------------------------------
51 // This is an asynchronous waiter which posts a task to a MessageLoop when 54 // This is an asynchronous waiter which posts a task to a MessageLoop when
52 // fired. An AsyncWaiter may only be in a single wait-list. 55 // fired. An AsyncWaiter may only be in a single wait-list.
53 // ----------------------------------------------------------------------------- 56 // -----------------------------------------------------------------------------
54 class AsyncWaiter : public WaitableEvent::Waiter { 57 class AsyncWaiter : public WaitableEvent::Waiter {
55 public: 58 public:
56 AsyncWaiter(MessageLoop* message_loop, 59 AsyncWaiter(MessageLoop* message_loop,
57 const base::Closure& callback, 60 const base::Closure& callback,
58 Flag* flag) 61 Flag* flag)
59 : message_loop_(message_loop), 62 : message_loop_(message_loop),
60 callback_(callback), 63 callback_(callback),
61 flag_(flag) { } 64 flag_(flag) { }
62 65
63 bool Fire(WaitableEvent* event) { 66 virtual bool Fire(WaitableEvent* event) OVERRIDE {
64 // Post the callback if we haven't been cancelled. 67 // Post the callback if we haven't been cancelled.
65 if (!flag_->value()) { 68 if (!flag_->value()) {
66 message_loop_->PostTask(FROM_HERE, callback_); 69 message_loop_->PostTask(FROM_HERE, callback_);
67 } 70 }
68 71
69 // We are removed from the wait-list by the WaitableEvent itself. It only 72 // We are removed from the wait-list by the WaitableEvent itself. It only
70 // remains to delete ourselves. 73 // remains to delete ourselves.
71 delete this; 74 delete this;
72 75
73 // We can always return true because an AsyncWaiter is never in two 76 // We can always return true because an AsyncWaiter is never in two
74 // different wait-lists at the same time. 77 // different wait-lists at the same time.
75 return true; 78 return true;
76 } 79 }
77 80
78 // See StopWatching for discussion 81 // See StopWatching for discussion
79 bool Compare(void* tag) { 82 virtual bool Compare(void* tag) OVERRIDE {
80 return tag == flag_.get(); 83 return tag == flag_.get();
81 } 84 }
82 85
83 private: 86 private:
84 MessageLoop *const message_loop_; 87 MessageLoop *const message_loop_;
85 base::Closure callback_; 88 base::Closure callback_;
86 scoped_refptr<Flag> flag_; 89 scoped_refptr<Flag> flag_;
87 }; 90 };
88 91
89 // ----------------------------------------------------------------------------- 92 // -----------------------------------------------------------------------------
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 // ----------------------------------------------------------------------------- 259 // -----------------------------------------------------------------------------
257 // This is called when the MessageLoop which the callback will be run it is 260 // This is called when the MessageLoop which the callback will be run it is
258 // deleted. We need to cancel the callback as if we had been deleted, but we 261 // deleted. We need to cancel the callback as if we had been deleted, but we
259 // will still be deleted at some point in the future. 262 // will still be deleted at some point in the future.
260 // ----------------------------------------------------------------------------- 263 // -----------------------------------------------------------------------------
261 void WaitableEventWatcher::WillDestroyCurrentMessageLoop() { 264 void WaitableEventWatcher::WillDestroyCurrentMessageLoop() {
262 StopWatching(); 265 StopWatching();
263 } 266 }
264 267
265 } // namespace base 268 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698