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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 | 97 |
98 // Broadcast() revives all waiting threads. | 98 // Broadcast() revives all waiting threads. |
99 void Broadcast(); | 99 void Broadcast(); |
100 // Signal() revives one waiting thread. | 100 // Signal() revives one waiting thread. |
101 void Signal(); | 101 void Signal(); |
102 | 102 |
103 private: | 103 private: |
104 | 104 |
105 #if defined(OS_WIN) | 105 #if defined(OS_WIN) |
106 CONDITION_VARIABLE cv_; | 106 CONDITION_VARIABLE cv_; |
107 CRITICAL_SECTION* const crit_sec_; | 107 SRWLOCK* const srwlock_; |
108 #elif defined(OS_POSIX) | 108 #elif defined(OS_POSIX) |
109 pthread_cond_t condition_; | 109 pthread_cond_t condition_; |
110 pthread_mutex_t* user_mutex_; | 110 pthread_mutex_t* user_mutex_; |
111 #endif | 111 #endif |
112 | 112 |
113 #if DCHECK_IS_ON() && (defined(OS_WIN) || defined(OS_POSIX)) | 113 #if DCHECK_IS_ON() && (defined(OS_WIN) || defined(OS_POSIX)) |
114 base::Lock* const user_lock_; // Needed to adjust shadow lock state on wait. | 114 base::Lock* const user_lock_; // Needed to adjust shadow lock state on wait. |
115 #endif | 115 #endif |
116 | 116 |
117 DISALLOW_COPY_AND_ASSIGN(ConditionVariable); | 117 DISALLOW_COPY_AND_ASSIGN(ConditionVariable); |
118 }; | 118 }; |
119 | 119 |
120 } // namespace base | 120 } // namespace base |
121 | 121 |
122 #endif // BASE_SYNCHRONIZATION_CONDITION_VARIABLE_H_ | 122 #endif // BASE_SYNCHRONIZATION_CONDITION_VARIABLE_H_ |
OLD | NEW |