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 <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include "base/base_export.h" | 10 #include "base/base_export.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
13 | 13 |
14 #if defined(OS_WIN) | 14 #if defined(OS_WIN) |
15 #include "base/win/scoped_handle.h" | 15 #include "base/win/scoped_handle.h" |
16 #endif | 16 #endif |
17 | 17 |
18 #if defined(OS_POSIX) | 18 #if defined(OS_POSIX) |
19 #include <list> | 19 #include <list> |
20 #include <utility> | 20 #include <utility> |
21 #include "base/memory/ref_counted.h" | 21 #include "base/memory/ref_counted.h" |
22 #include "base/synchronization/lock.h" | 22 #include "base/synchronization/lock.h" |
23 #endif | 23 #endif |
24 | 24 |
25 namespace base { | 25 namespace base { |
26 | 26 |
27 class TimeDelta; | 27 class TimeDelta; |
| 28 class TimeTicks; |
28 | 29 |
29 // A WaitableEvent can be a useful thread synchronization tool when you want to | 30 // A WaitableEvent can be a useful thread synchronization tool when you want to |
30 // allow one thread to wait for another thread to finish some work. For | 31 // allow one thread to wait for another thread to finish some work. For |
31 // non-Windows systems, this can only be used from within a single address | 32 // non-Windows systems, this can only be used from within a single address |
32 // space. | 33 // space. |
33 // | 34 // |
34 // Use a WaitableEvent when you would otherwise use a Lock+ConditionVariable to | 35 // Use a WaitableEvent when you would otherwise use a Lock+ConditionVariable to |
35 // protect a simple boolean value. However, if you find yourself using a | 36 // protect a simple boolean value. However, if you find yourself using a |
36 // WaitableEvent in conjunction with a Lock to wait for a more complex state | 37 // WaitableEvent in conjunction with a Lock to wait for a more complex state |
37 // change (e.g., for an item to be added to a queue), then you should probably | 38 // change (e.g., for an item to be added to a queue), then you should probably |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 // Wait indefinitely for the event to be signaled. Wait's return "happens | 80 // Wait indefinitely for the event to be signaled. Wait's return "happens |
80 // after" |Signal| has completed. This means that it's safe for a | 81 // after" |Signal| has completed. This means that it's safe for a |
81 // WaitableEvent to synchronise its own destruction, like this: | 82 // WaitableEvent to synchronise its own destruction, like this: |
82 // | 83 // |
83 // WaitableEvent *e = new WaitableEvent; | 84 // WaitableEvent *e = new WaitableEvent; |
84 // SendToOtherThread(e); | 85 // SendToOtherThread(e); |
85 // e->Wait(); | 86 // e->Wait(); |
86 // delete e; | 87 // delete e; |
87 void Wait(); | 88 void Wait(); |
88 | 89 |
89 // Wait up until max_time has passed for the event to be signaled. Returns | 90 // Wait up until wait_delta has passed for the event to be signaled. Returns |
90 // true if the event was signaled. If this method returns false, then it | 91 // true if the event was signaled. |
91 // does not necessarily mean that max_time was exceeded. | |
92 // | 92 // |
93 // TimedWait can synchronise its own destruction like |Wait|. | 93 // TimedWait can synchronise its own destruction like |Wait|. |
94 bool TimedWait(const TimeDelta& max_time); | 94 bool TimedWait(const TimeDelta& wait_delta); |
| 95 |
| 96 // Wait up until end_time deadline has passed for the event to be signaled. |
| 97 // Return true if the event was signaled. |
| 98 // |
| 99 // TimedWaitUntil can synchronise its own destruction like |Wait|. |
| 100 bool TimedWaitUntil(const TimeTicks& end_time); |
95 | 101 |
96 #if defined(OS_WIN) | 102 #if defined(OS_WIN) |
97 HANDLE handle() const { return handle_.Get(); } | 103 HANDLE handle() const { return handle_.Get(); } |
98 #endif | 104 #endif |
99 | 105 |
100 // Wait, synchronously, on multiple events. | 106 // Wait, synchronously, on multiple events. |
101 // waitables: an array of WaitableEvent pointers | 107 // waitables: an array of WaitableEvent pointers |
102 // count: the number of elements in @waitables | 108 // count: the number of elements in @waitables |
103 // | 109 // |
104 // returns: the index of a WaitableEvent which has been signaled. | 110 // returns: the index of a WaitableEvent which has been signaled. |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 | 193 |
188 scoped_refptr<WaitableEventKernel> kernel_; | 194 scoped_refptr<WaitableEventKernel> kernel_; |
189 #endif | 195 #endif |
190 | 196 |
191 DISALLOW_COPY_AND_ASSIGN(WaitableEvent); | 197 DISALLOW_COPY_AND_ASSIGN(WaitableEvent); |
192 }; | 198 }; |
193 | 199 |
194 } // namespace base | 200 } // namespace base |
195 | 201 |
196 #endif // BASE_SYNCHRONIZATION_WAITABLE_EVENT_H_ | 202 #endif // BASE_SYNCHRONIZATION_WAITABLE_EVENT_H_ |
OLD | NEW |