OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project 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 V8_BASE_PLATFORM_CONDITION_VARIABLE_H_ | 5 #ifndef V8_BASE_PLATFORM_CONDITION_VARIABLE_H_ |
6 #define V8_BASE_PLATFORM_CONDITION_VARIABLE_H_ | 6 #define V8_BASE_PLATFORM_CONDITION_VARIABLE_H_ |
7 | 7 |
8 #include "src/base/base-export.h" | |
9 #include "src/base/lazy-instance.h" | 8 #include "src/base/lazy-instance.h" |
10 #include "src/base/platform/mutex.h" | 9 #include "src/base/platform/mutex.h" |
11 | 10 |
12 namespace v8 { | 11 namespace v8 { |
13 namespace base { | 12 namespace base { |
14 | 13 |
15 // Forward declarations. | 14 // Forward declarations. |
16 class ConditionVariableEvent; | 15 class ConditionVariableEvent; |
17 class TimeDelta; | 16 class TimeDelta; |
18 | 17 |
19 // ----------------------------------------------------------------------------- | 18 // ----------------------------------------------------------------------------- |
20 // ConditionVariable | 19 // ConditionVariable |
21 // | 20 // |
22 // This class is a synchronization primitive that can be used to block a thread, | 21 // This class is a synchronization primitive that can be used to block a thread, |
23 // or multiple threads at the same time, until: | 22 // or multiple threads at the same time, until: |
24 // - a notification is received from another thread, | 23 // - a notification is received from another thread, |
25 // - a timeout expires, or | 24 // - a timeout expires, or |
26 // - a spurious wakeup occurs | 25 // - a spurious wakeup occurs |
27 // Any thread that intends to wait on a ConditionVariable has to acquire a lock | 26 // Any thread that intends to wait on a ConditionVariable has to acquire a lock |
28 // on a Mutex first. The |Wait()| and |WaitFor()| operations atomically release | 27 // on a Mutex first. The |Wait()| and |WaitFor()| operations atomically release |
29 // the mutex and suspend the execution of the calling thread. When the condition | 28 // the mutex and suspend the execution of the calling thread. When the condition |
30 // variable is notified, the thread is awakened, and the mutex is reacquired. | 29 // variable is notified, the thread is awakened, and the mutex is reacquired. |
31 | 30 |
32 class V8_BASE_EXPORT ConditionVariable final { | 31 class ConditionVariable final { |
33 public: | 32 public: |
34 ConditionVariable(); | 33 ConditionVariable(); |
35 ~ConditionVariable(); | 34 ~ConditionVariable(); |
36 | 35 |
37 // If any threads are waiting on this condition variable, calling | 36 // If any threads are waiting on this condition variable, calling |
38 // |NotifyOne()| unblocks one of the waiting threads. | 37 // |NotifyOne()| unblocks one of the waiting threads. |
39 void NotifyOne(); | 38 void NotifyOne(); |
40 | 39 |
41 // Unblocks all threads currently waiting for this condition variable. | 40 // Unblocks all threads currently waiting for this condition variable. |
42 void NotifyAll(); | 41 void NotifyAll(); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 typedef LazyStaticInstance< | 110 typedef LazyStaticInstance< |
112 ConditionVariable, DefaultConstructTrait<ConditionVariable>, | 111 ConditionVariable, DefaultConstructTrait<ConditionVariable>, |
113 ThreadSafeInitOnceTrait>::type LazyConditionVariable; | 112 ThreadSafeInitOnceTrait>::type LazyConditionVariable; |
114 | 113 |
115 #define LAZY_CONDITION_VARIABLE_INITIALIZER LAZY_STATIC_INSTANCE_INITIALIZER | 114 #define LAZY_CONDITION_VARIABLE_INITIALIZER LAZY_STATIC_INSTANCE_INITIALIZER |
116 | 115 |
117 } // namespace base | 116 } // namespace base |
118 } // namespace v8 | 117 } // namespace v8 |
119 | 118 |
120 #endif // V8_BASE_PLATFORM_CONDITION_VARIABLE_H_ | 119 #endif // V8_BASE_PLATFORM_CONDITION_VARIABLE_H_ |
OLD | NEW |