OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_SYNCHRONIZATION_WAITABLE_EVENT_H_ | 5 #ifndef BASE_SYNCHRONIZATION_WAITABLE_EVENT_H_ |
6 #define BASE_SYNCHRONIZATION_WAITABLE_EVENT_H_ | 6 #define BASE_SYNCHRONIZATION_WAITABLE_EVENT_H_ |
7 | 7 |
8 #include "base/base_export.h" | 8 #include "base/base_export.h" |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 | 10 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 void Reset(); | 65 void Reset(); |
66 | 66 |
67 // Put the event in the signaled state. Causing any thread blocked on Wait | 67 // Put the event in the signaled state. Causing any thread blocked on Wait |
68 // to be woken up. | 68 // to be woken up. |
69 void Signal(); | 69 void Signal(); |
70 | 70 |
71 // Returns true if the event is in the signaled state, else false. If this | 71 // Returns true if the event is in the signaled state, else false. If this |
72 // is not a manual reset event, then this test will cause a reset. | 72 // is not a manual reset event, then this test will cause a reset. |
73 bool IsSignaled(); | 73 bool IsSignaled(); |
74 | 74 |
75 // Wait indefinitely for the event to be signaled. | 75 // Wait indefinitely for the event to be signaled. Wait's return "happens |
| 76 // after" |Signal| has completed. This means that it's safe for a |
| 77 // WaitableEvent to synchronise its own destruction, like this: |
| 78 // |
| 79 // WaitableEvent *e = new WaitableEvent; |
| 80 // SendToOtherThread(e); |
| 81 // e->Wait(); |
| 82 // delete e; |
76 void Wait(); | 83 void Wait(); |
77 | 84 |
78 // Wait up until max_time has passed for the event to be signaled. Returns | 85 // Wait up until max_time has passed for the event to be signaled. Returns |
79 // true if the event was signaled. If this method returns false, then it | 86 // true if the event was signaled. If this method returns false, then it |
80 // does not necessarily mean that max_time was exceeded. | 87 // does not necessarily mean that max_time was exceeded. |
| 88 // |
| 89 // TimedWait can synchronise its own destruction like |Wait|. |
81 bool TimedWait(const TimeDelta& max_time); | 90 bool TimedWait(const TimeDelta& max_time); |
82 | 91 |
83 #if defined(OS_WIN) | 92 #if defined(OS_WIN) |
84 HANDLE handle() const { return handle_; } | 93 HANDLE handle() const { return handle_; } |
85 #endif | 94 #endif |
86 | 95 |
87 // Wait, synchronously, on multiple events. | 96 // Wait, synchronously, on multiple events. |
88 // waitables: an array of WaitableEvent pointers | 97 // waitables: an array of WaitableEvent pointers |
89 // count: the number of elements in @waitables | 98 // count: the number of elements in @waitables |
90 // | 99 // |
91 // returns: the index of a WaitableEvent which has been signaled. | 100 // returns: the index of a WaitableEvent which has been signaled. |
92 // | 101 // |
93 // You MUST NOT delete any of the WaitableEvent objects while this wait is | 102 // You MUST NOT delete any of the WaitableEvent objects while this wait is |
94 // happening. | 103 // happening, however WaitMany's return "happens after" the |Signal| call |
| 104 // that caused it has completed, like |Wait|. |
95 static size_t WaitMany(WaitableEvent** waitables, size_t count); | 105 static size_t WaitMany(WaitableEvent** waitables, size_t count); |
96 | 106 |
97 // For asynchronous waiting, see WaitableEventWatcher | 107 // For asynchronous waiting, see WaitableEventWatcher |
98 | 108 |
99 // This is a private helper class. It's here because it's used by friends of | 109 // This is a private helper class. It's here because it's used by friends of |
100 // this class (such as WaitableEventWatcher) to be able to enqueue elements | 110 // this class (such as WaitableEventWatcher) to be able to enqueue elements |
101 // of the wait-list | 111 // of the wait-list |
102 class Waiter { | 112 class Waiter { |
103 public: | 113 public: |
104 // Signal the waiter to wake up. | 114 // Signal the waiter to wake up. |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 | 183 |
174 scoped_refptr<WaitableEventKernel> kernel_; | 184 scoped_refptr<WaitableEventKernel> kernel_; |
175 #endif | 185 #endif |
176 | 186 |
177 DISALLOW_COPY_AND_ASSIGN(WaitableEvent); | 187 DISALLOW_COPY_AND_ASSIGN(WaitableEvent); |
178 }; | 188 }; |
179 | 189 |
180 } // namespace base | 190 } // namespace base |
181 | 191 |
182 #endif // BASE_SYNCHRONIZATION_WAITABLE_EVENT_H_ | 192 #endif // BASE_SYNCHRONIZATION_WAITABLE_EVENT_H_ |
OLD | NEW |