| 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 <errno.h> | 7 #include <errno.h> |
| 8 #include <stdint.h> |
| 8 #include <sys/time.h> | 9 #include <sys/time.h> |
| 9 | 10 |
| 10 #include "base/synchronization/lock.h" | 11 #include "base/synchronization/lock.h" |
| 11 #include "base/threading/thread_restrictions.h" | 12 #include "base/threading/thread_restrictions.h" |
| 12 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "build/build_config.h" |
| 13 | 15 |
| 14 namespace base { | 16 namespace base { |
| 15 | 17 |
| 16 ConditionVariable::ConditionVariable(Lock* user_lock) | 18 ConditionVariable::ConditionVariable(Lock* user_lock) |
| 17 : user_mutex_(user_lock->lock_.native_handle()) | 19 : user_mutex_(user_lock->lock_.native_handle()) |
| 18 #if DCHECK_IS_ON() | 20 #if DCHECK_IS_ON() |
| 19 , user_lock_(user_lock) | 21 , user_lock_(user_lock) |
| 20 #endif | 22 #endif |
| 21 { | 23 { |
| 22 int rv = 0; | 24 int rv = 0; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 #endif | 68 #endif |
| 67 int rv = pthread_cond_wait(&condition_, user_mutex_); | 69 int rv = pthread_cond_wait(&condition_, user_mutex_); |
| 68 DCHECK_EQ(0, rv); | 70 DCHECK_EQ(0, rv); |
| 69 #if DCHECK_IS_ON() | 71 #if DCHECK_IS_ON() |
| 70 user_lock_->CheckUnheldAndMark(); | 72 user_lock_->CheckUnheldAndMark(); |
| 71 #endif | 73 #endif |
| 72 } | 74 } |
| 73 | 75 |
| 74 void ConditionVariable::TimedWait(const TimeDelta& max_time) { | 76 void ConditionVariable::TimedWait(const TimeDelta& max_time) { |
| 75 base::ThreadRestrictions::AssertWaitAllowed(); | 77 base::ThreadRestrictions::AssertWaitAllowed(); |
| 76 int64 usecs = max_time.InMicroseconds(); | 78 int64_t usecs = max_time.InMicroseconds(); |
| 77 struct timespec relative_time; | 79 struct timespec relative_time; |
| 78 relative_time.tv_sec = usecs / Time::kMicrosecondsPerSecond; | 80 relative_time.tv_sec = usecs / Time::kMicrosecondsPerSecond; |
| 79 relative_time.tv_nsec = | 81 relative_time.tv_nsec = |
| 80 (usecs % Time::kMicrosecondsPerSecond) * Time::kNanosecondsPerMicrosecond; | 82 (usecs % Time::kMicrosecondsPerSecond) * Time::kNanosecondsPerMicrosecond; |
| 81 | 83 |
| 82 #if DCHECK_IS_ON() | 84 #if DCHECK_IS_ON() |
| 83 user_lock_->CheckHeldAndUnmark(); | 85 user_lock_->CheckHeldAndUnmark(); |
| 84 #endif | 86 #endif |
| 85 | 87 |
| 86 #if defined(OS_MACOSX) | 88 #if defined(OS_MACOSX) |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 int rv = pthread_cond_broadcast(&condition_); | 128 int rv = pthread_cond_broadcast(&condition_); |
| 127 DCHECK_EQ(0, rv); | 129 DCHECK_EQ(0, rv); |
| 128 } | 130 } |
| 129 | 131 |
| 130 void ConditionVariable::Signal() { | 132 void ConditionVariable::Signal() { |
| 131 int rv = pthread_cond_signal(&condition_); | 133 int rv = pthread_cond_signal(&condition_); |
| 132 DCHECK_EQ(0, rv); | 134 DCHECK_EQ(0, rv); |
| 133 } | 135 } |
| 134 | 136 |
| 135 } // namespace base | 137 } // namespace base |
| OLD | NEW |