OLD | NEW |
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 // ConditionVariable wraps pthreads condition variable synchronization or, on | 5 // ConditionVariable wraps pthreads condition variable synchronization or, on |
6 // Windows, simulates it. This functionality is very helpful for having | 6 // Windows, simulates it. This functionality is very helpful for having |
7 // several threads wait for an event, as is common with a thread pool managed | 7 // several threads wait for an event, as is common with a thread pool managed |
8 // by a master. The meaning of such an event in the (worker) thread pool | 8 // by a master. The meaning of such an event in the (worker) thread pool |
9 // scenario is that additional tasks are now available for processing. It is | 9 // scenario is that additional tasks are now available for processing. It is |
10 // used in Chrome in the DNS prefetching system to notify worker threads that | 10 // used in Chrome in the DNS prefetching system to notify worker threads that |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 #pragma once | 67 #pragma once |
68 | 68 |
69 #include "build/build_config.h" | 69 #include "build/build_config.h" |
70 | 70 |
71 #if defined(OS_WIN) | 71 #if defined(OS_WIN) |
72 #include <windows.h> | 72 #include <windows.h> |
73 #elif defined(OS_POSIX) | 73 #elif defined(OS_POSIX) |
74 #include <pthread.h> | 74 #include <pthread.h> |
75 #endif | 75 #endif |
76 | 76 |
| 77 #include "base/base_api.h" |
77 #include "base/basictypes.h" | 78 #include "base/basictypes.h" |
78 #include "base/synchronization/lock.h" | 79 #include "base/synchronization/lock.h" |
79 | 80 |
80 namespace base { | 81 namespace base { |
81 | 82 |
82 class TimeDelta; | 83 class TimeDelta; |
83 | 84 |
84 class ConditionVariable { | 85 class BASE_API ConditionVariable { |
85 public: | 86 public: |
86 // Construct a cv for use with ONLY one user lock. | 87 // Construct a cv for use with ONLY one user lock. |
87 explicit ConditionVariable(Lock* user_lock); | 88 explicit ConditionVariable(Lock* user_lock); |
88 | 89 |
89 ~ConditionVariable(); | 90 ~ConditionVariable(); |
90 | 91 |
91 // Wait() releases the caller's critical section atomically as it starts to | 92 // Wait() releases the caller's critical section atomically as it starts to |
92 // sleep, and the reacquires it when it is signaled. | 93 // sleep, and the reacquires it when it is signaled. |
93 void Wait(); | 94 void Wait(); |
94 void TimedWait(const TimeDelta& max_time); | 95 void TimedWait(const TimeDelta& max_time); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 #endif | 181 #endif |
181 | 182 |
182 #endif | 183 #endif |
183 | 184 |
184 DISALLOW_COPY_AND_ASSIGN(ConditionVariable); | 185 DISALLOW_COPY_AND_ASSIGN(ConditionVariable); |
185 }; | 186 }; |
186 | 187 |
187 } // namespace base | 188 } // namespace base |
188 | 189 |
189 #endif // BASE_SYNCHRONIZATION_CONDITION_VARIABLE_H_ | 190 #endif // BASE_SYNCHRONIZATION_CONDITION_VARIABLE_H_ |
OLD | NEW |