| 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 "base/synchronization/lock.h" | 7 #include "base/synchronization/lock.h" |
| 8 #include "base/threading/thread_restrictions.h" | 8 #include "base/threading/thread_restrictions.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 | 10 |
| 11 namespace base { | 11 namespace base { |
| 12 | 12 |
| 13 ConditionVariable::ConditionVariable(Lock* user_lock) | 13 ConditionVariable::ConditionVariable(Lock* user_lock) |
| 14 : crit_sec_(user_lock->lock_.native_handle()) | 14 : srwlock_(user_lock->lock_.native_handle()) |
| 15 #if DCHECK_IS_ON() | 15 #if DCHECK_IS_ON() |
| 16 , user_lock_(user_lock) | 16 , user_lock_(user_lock) |
| 17 #endif | 17 #endif |
| 18 { | 18 { |
| 19 DCHECK(user_lock); | 19 DCHECK(user_lock); |
| 20 InitializeConditionVariable(&cv_); | 20 InitializeConditionVariable(&cv_); |
| 21 } | 21 } |
| 22 | 22 |
| 23 ConditionVariable::~ConditionVariable() = default; | 23 ConditionVariable::~ConditionVariable() = default; |
| 24 | 24 |
| 25 void ConditionVariable::Wait() { | 25 void ConditionVariable::Wait() { |
| 26 TimedWait(TimeDelta::FromMilliseconds(INFINITE)); | 26 TimedWait(TimeDelta::FromMilliseconds(INFINITE)); |
| 27 } | 27 } |
| 28 | 28 |
| 29 void ConditionVariable::TimedWait(const TimeDelta& max_time) { | 29 void ConditionVariable::TimedWait(const TimeDelta& max_time) { |
| 30 base::ThreadRestrictions::AssertWaitAllowed(); | 30 base::ThreadRestrictions::AssertWaitAllowed(); |
| 31 DWORD timeout = static_cast<DWORD>(max_time.InMilliseconds()); | 31 DWORD timeout = static_cast<DWORD>(max_time.InMilliseconds()); |
| 32 | 32 |
| 33 #if DCHECK_IS_ON() | 33 #if DCHECK_IS_ON() |
| 34 user_lock_->CheckHeldAndUnmark(); | 34 user_lock_->CheckHeldAndUnmark(); |
| 35 #endif | 35 #endif |
| 36 | 36 |
| 37 if (FALSE == SleepConditionVariableCS(&cv_, crit_sec_, timeout)) { | 37 if (FALSE == SleepConditionVariableSRW(&cv_, srwlock_, timeout, 0)) { |
| 38 DCHECK(GetLastError() != WAIT_TIMEOUT); | 38 DCHECK(GetLastError() != WAIT_TIMEOUT); |
| 39 } | 39 } |
| 40 | 40 |
| 41 #if DCHECK_IS_ON() | 41 #if DCHECK_IS_ON() |
| 42 user_lock_->CheckUnheldAndMark(); | 42 user_lock_->CheckUnheldAndMark(); |
| 43 #endif | 43 #endif |
| 44 } | 44 } |
| 45 | 45 |
| 46 void ConditionVariable::Broadcast() { | 46 void ConditionVariable::Broadcast() { |
| 47 WakeAllConditionVariable(&cv_); | 47 WakeAllConditionVariable(&cv_); |
| 48 } | 48 } |
| 49 | 49 |
| 50 void ConditionVariable::Signal() { | 50 void ConditionVariable::Signal() { |
| 51 WakeConditionVariable(&cv_); | 51 WakeConditionVariable(&cv_); |
| 52 } | 52 } |
| 53 | 53 |
| 54 } // namespace base | 54 } // namespace base |
| OLD | NEW |