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 #include "base/synchronization/condition_variable.h" | 5 #include "base/synchronization/condition_variable.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <stack> | 8 #include <stack> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
13 #include "base/threading/thread_restrictions.h" | |
13 #include "base/time.h" | 14 #include "base/time.h" |
14 | 15 |
15 namespace { | 16 namespace { |
16 // We can't use the linker supported delay-load for kernel32 so all this | 17 // We can't use the linker supported delay-load for kernel32 so all this |
17 // cruft here is to manually late-bind the needed functions. | 18 // cruft here is to manually late-bind the needed functions. |
18 typedef void (WINAPI *InitializeConditionVariableFn)(PCONDITION_VARIABLE); | 19 typedef void (WINAPI *InitializeConditionVariableFn)(PCONDITION_VARIABLE); |
19 typedef BOOL (WINAPI *SleepConditionVariableCSFn)(PCONDITION_VARIABLE, | 20 typedef BOOL (WINAPI *SleepConditionVariableCSFn)(PCONDITION_VARIABLE, |
20 PCRITICAL_SECTION, DWORD); | 21 PCRITICAL_SECTION, DWORD); |
21 typedef void (WINAPI *WakeConditionVariableFn)(PCONDITION_VARIABLE); | 22 typedef void (WINAPI *WakeConditionVariableFn)(PCONDITION_VARIABLE); |
22 typedef void (WINAPI *WakeAllConditionVariableFn)(PCONDITION_VARIABLE); | 23 typedef void (WINAPI *WakeAllConditionVariableFn)(PCONDITION_VARIABLE); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
87 : user_lock_(*user_lock) { | 88 : user_lock_(*user_lock) { |
88 initialize_condition_variable_fn(&cv_); | 89 initialize_condition_variable_fn(&cv_); |
89 DCHECK(user_lock); | 90 DCHECK(user_lock); |
90 } | 91 } |
91 | 92 |
92 void WinVistaCondVar::Wait() { | 93 void WinVistaCondVar::Wait() { |
93 TimedWait(TimeDelta::FromMilliseconds(INFINITE)); | 94 TimedWait(TimeDelta::FromMilliseconds(INFINITE)); |
94 } | 95 } |
95 | 96 |
96 void WinVistaCondVar::TimedWait(const TimeDelta& max_time) { | 97 void WinVistaCondVar::TimedWait(const TimeDelta& max_time) { |
98 base::ThreadRestrictions::AssertWaitAllowed(); | |
97 DWORD timeout = static_cast<DWORD>(max_time.InMilliseconds()); | 99 DWORD timeout = static_cast<DWORD>(max_time.InMilliseconds()); |
98 CRITICAL_SECTION* cs = user_lock_.lock_.os_lock(); | 100 CRITICAL_SECTION* cs = user_lock_.lock_.os_lock(); |
99 | 101 |
100 #if !defined(NDEBUG) | 102 #if !defined(NDEBUG) |
101 user_lock_.CheckHeldAndUnmark(); | 103 user_lock_.CheckHeldAndUnmark(); |
102 #endif | 104 #endif |
103 | 105 |
104 if (FALSE == sleep_condition_variable_fn(&cv_, cs, timeout)) { | 106 if (FALSE == sleep_condition_variable_fn(&cv_, cs, timeout)) { |
105 DCHECK(GetLastError() != WAIT_TIMEOUT); | 107 DCHECK(GetLastError() != WAIT_TIMEOUT); |
106 } | 108 } |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
232 | 234 |
233 DCHECK_EQ(recycling_list_size_, allocation_counter_); | 235 DCHECK_EQ(recycling_list_size_, allocation_counter_); |
234 } | 236 } |
235 | 237 |
236 void WinXPCondVar::Wait() { | 238 void WinXPCondVar::Wait() { |
237 // Default to "wait forever" timing, which means have to get a Signal() | 239 // Default to "wait forever" timing, which means have to get a Signal() |
238 // or Broadcast() to come out of this wait state. | 240 // or Broadcast() to come out of this wait state. |
239 TimedWait(TimeDelta::FromMilliseconds(INFINITE)); | 241 TimedWait(TimeDelta::FromMilliseconds(INFINITE)); |
240 } | 242 } |
241 | 243 |
242 void WinXPCondVar::TimedWait(const TimeDelta& max_time) { | 244 void WinXPCondVar::TimedWait(const TimeDelta& max_time) { |
brettw
2012/04/25 05:41:14
Do you also want to add the assert to the XP imple
jam
2012/04/25 22:56:46
Done.
| |
243 Event* waiting_event; | 245 Event* waiting_event; |
244 HANDLE handle; | 246 HANDLE handle; |
245 { | 247 { |
246 AutoLock auto_lock(internal_lock_); | 248 AutoLock auto_lock(internal_lock_); |
247 if (RUNNING != run_state_) return; // Destruction in progress. | 249 if (RUNNING != run_state_) return; // Destruction in progress. |
248 waiting_event = GetEventForWaiting(); | 250 waiting_event = GetEventForWaiting(); |
249 handle = waiting_event->handle(); | 251 handle = waiting_event->handle(); |
250 DCHECK(handle); | 252 DCHECK(handle); |
251 } // Release internal_lock. | 253 } // Release internal_lock. |
252 | 254 |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
657 | 659 |
658 void ConditionVariable::Broadcast() { | 660 void ConditionVariable::Broadcast() { |
659 impl_->Broadcast(); | 661 impl_->Broadcast(); |
660 } | 662 } |
661 | 663 |
662 void ConditionVariable::Signal() { | 664 void ConditionVariable::Signal() { |
663 impl_->Signal(); | 665 impl_->Signal(); |
664 } | 666 } |
665 | 667 |
666 } // namespace base | 668 } // namespace base |
OLD | NEW |