OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #ifndef BASE_WAITABLE_EVENT_WATCHER_H_ | 5 #ifndef BASE_WAITABLE_EVENT_WATCHER_H_ |
6 #define BASE_WAITABLE_EVENT_WATCHER_H_ | 6 #define BASE_WAITABLE_EVENT_WATCHER_H_ |
7 | 7 |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 | 9 |
10 #if defined(OS_WIN) | 10 #if defined(OS_WIN) |
11 #include "base/object_watcher.h" | 11 #include "base/object_watcher.h" |
12 #else | 12 #else |
13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 14 #include "base/waitable_event.h" |
14 #endif | 15 #endif |
15 | 16 |
16 namespace base { | 17 namespace base { |
17 | 18 |
18 class WaitableEvent; | |
19 class Flag; | 19 class Flag; |
20 class AsyncWaiter; | 20 class AsyncWaiter; |
21 class AsyncCallbackTask; | 21 class AsyncCallbackTask; |
22 | 22 |
23 // ----------------------------------------------------------------------------- | 23 // ----------------------------------------------------------------------------- |
24 // This class provides a way to wait on a WaitableEvent asynchronously. | 24 // This class provides a way to wait on a WaitableEvent asynchronously. |
25 // | 25 // |
26 // Each instance of this object can be waiting on a single WaitableEvent. When | 26 // Each instance of this object can be waiting on a single WaitableEvent. When |
27 // the waitable event is signaled, a callback is made in the thread of a given | 27 // the waitable event is signaled, a callback is made in the thread of a given |
28 // MessageLoop. This callback can be deleted by deleting the waiter. | 28 // MessageLoop. This callback can be deleted by deleting the waiter. |
(...skipping 15 matching lines...) Expand all Loading... |
44 // In the above example, MyClass wants to "do stuff" when waitable_event | 44 // In the above example, MyClass wants to "do stuff" when waitable_event |
45 // becomes signaled. WaitableEventWatcher makes this task easy. When MyClass | 45 // becomes signaled. WaitableEventWatcher makes this task easy. When MyClass |
46 // goes out of scope, the watcher_ will be destroyed, and there is no need to | 46 // goes out of scope, the watcher_ will be destroyed, and there is no need to |
47 // worry about OnWaitableEventSignaled being called on a deleted MyClass | 47 // worry about OnWaitableEventSignaled being called on a deleted MyClass |
48 // pointer. | 48 // pointer. |
49 // | 49 // |
50 // BEWARE: With automatically reset WaitableEvents, a signal may be lost if it | 50 // BEWARE: With automatically reset WaitableEvents, a signal may be lost if it |
51 // occurs just before a WaitableEventWatcher is deleted. There is currently no | 51 // occurs just before a WaitableEventWatcher is deleted. There is currently no |
52 // safe way to stop watching an automatic reset WaitableEvent without possibly | 52 // safe way to stop watching an automatic reset WaitableEvent without possibly |
53 // missing a signal. | 53 // missing a signal. |
| 54 // |
| 55 // NOTE: you /are/ allowed to delete the WaitableEvent while still waiting on |
| 56 // it with a Watcher. It will act as if the event was never signaled. |
54 // ----------------------------------------------------------------------------- | 57 // ----------------------------------------------------------------------------- |
55 | 58 |
56 class WaitableEventWatcher | 59 class WaitableEventWatcher |
57 #if defined(OS_POSIX) | 60 #if defined(OS_POSIX) |
58 : public MessageLoop::DestructionObserver | 61 : public MessageLoop::DestructionObserver |
59 #endif | 62 #endif |
60 { | 63 { |
61 public: | 64 public: |
62 | 65 |
63 WaitableEventWatcher(); | 66 WaitableEventWatcher(); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 #else | 136 #else |
134 // --------------------------------------------------------------------------- | 137 // --------------------------------------------------------------------------- |
135 // Implementation of MessageLoop::DestructionObserver | 138 // Implementation of MessageLoop::DestructionObserver |
136 // --------------------------------------------------------------------------- | 139 // --------------------------------------------------------------------------- |
137 void WillDestroyCurrentMessageLoop(); | 140 void WillDestroyCurrentMessageLoop(); |
138 | 141 |
139 MessageLoop* message_loop_; | 142 MessageLoop* message_loop_; |
140 scoped_refptr<Flag> cancel_flag_; | 143 scoped_refptr<Flag> cancel_flag_; |
141 AsyncWaiter* waiter_; | 144 AsyncWaiter* waiter_; |
142 AsyncCallbackTask* callback_task_; | 145 AsyncCallbackTask* callback_task_; |
| 146 scoped_refptr<WaitableEvent::WaitableEventKernel> kernel_; |
143 #endif | 147 #endif |
144 }; | 148 }; |
145 | 149 |
146 } // namespace base | 150 } // namespace base |
147 | 151 |
148 #endif // BASE_WAITABLE_EVENT_WATCHER_H_ | 152 #endif // BASE_WAITABLE_EVENT_WATCHER_H_ |
OLD | NEW |