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 <stdint.h> |
9 #include <sys/time.h> | 9 #include <sys/time.h> |
10 | 10 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 #if DCHECK_IS_ON() | 66 #if DCHECK_IS_ON() |
67 user_lock_->CheckHeldAndUnmark(); | 67 user_lock_->CheckHeldAndUnmark(); |
68 #endif | 68 #endif |
69 int rv = pthread_cond_wait(&condition_, user_mutex_); | 69 int rv = pthread_cond_wait(&condition_, user_mutex_); |
70 DCHECK_EQ(0, rv); | 70 DCHECK_EQ(0, rv); |
71 #if DCHECK_IS_ON() | 71 #if DCHECK_IS_ON() |
72 user_lock_->CheckUnheldAndMark(); | 72 user_lock_->CheckUnheldAndMark(); |
73 #endif | 73 #endif |
74 } | 74 } |
75 | 75 |
76 void ConditionVariable::TimedWait(const TimeDelta& max_time) { | 76 bool ConditionVariable::TimedWait(const TimeDelta& max_time) { |
77 base::ThreadRestrictions::AssertWaitAllowed(); | 77 base::ThreadRestrictions::AssertWaitAllowed(); |
78 int64_t usecs = max_time.InMicroseconds(); | 78 int64_t usecs = max_time.InMicroseconds(); |
79 struct timespec relative_time; | 79 struct timespec relative_time; |
80 relative_time.tv_sec = usecs / Time::kMicrosecondsPerSecond; | 80 relative_time.tv_sec = usecs / Time::kMicrosecondsPerSecond; |
81 relative_time.tv_nsec = | 81 relative_time.tv_nsec = |
82 (usecs % Time::kMicrosecondsPerSecond) * Time::kNanosecondsPerMicrosecond; | 82 (usecs % Time::kMicrosecondsPerSecond) * Time::kNanosecondsPerMicrosecond; |
83 | 83 |
84 #if DCHECK_IS_ON() | 84 #if DCHECK_IS_ON() |
85 user_lock_->CheckHeldAndUnmark(); | 85 user_lock_->CheckHeldAndUnmark(); |
86 #endif | 86 #endif |
(...skipping 28 matching lines...) Expand all Loading... |
115 &condition_, user_mutex_, &absolute_time); | 115 &condition_, user_mutex_, &absolute_time); |
116 #else | 116 #else |
117 int rv = pthread_cond_timedwait(&condition_, user_mutex_, &absolute_time); | 117 int rv = pthread_cond_timedwait(&condition_, user_mutex_, &absolute_time); |
118 #endif // OS_ANDROID && HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC | 118 #endif // OS_ANDROID && HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC |
119 #endif // OS_MACOSX | 119 #endif // OS_MACOSX |
120 | 120 |
121 DCHECK(rv == 0 || rv == ETIMEDOUT); | 121 DCHECK(rv == 0 || rv == ETIMEDOUT); |
122 #if DCHECK_IS_ON() | 122 #if DCHECK_IS_ON() |
123 user_lock_->CheckUnheldAndMark(); | 123 user_lock_->CheckUnheldAndMark(); |
124 #endif | 124 #endif |
| 125 |
| 126 return rv == ETIMEDOUT; |
125 } | 127 } |
126 | 128 |
127 void ConditionVariable::Broadcast() { | 129 void ConditionVariable::Broadcast() { |
128 int rv = pthread_cond_broadcast(&condition_); | 130 int rv = pthread_cond_broadcast(&condition_); |
129 DCHECK_EQ(0, rv); | 131 DCHECK_EQ(0, rv); |
130 } | 132 } |
131 | 133 |
132 void ConditionVariable::Signal() { | 134 void ConditionVariable::Signal() { |
133 int rv = pthread_cond_signal(&condition_); | 135 int rv = pthread_cond_signal(&condition_); |
134 DCHECK_EQ(0, rv); | 136 DCHECK_EQ(0, rv); |
135 } | 137 } |
136 | 138 |
137 } // namespace base | 139 } // namespace base |
OLD | NEW |