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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 DCHECK_GE(absolute_time.tv_sec, now.tv_sec); // Overflow paranoia | 111 DCHECK_GE(absolute_time.tv_sec, now.tv_sec); // Overflow paranoia |
112 | 112 |
113 #if defined(OS_ANDROID) && defined(HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC) | 113 #if defined(OS_ANDROID) && defined(HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC) |
114 int rv = pthread_cond_timedwait_monotonic_np( | 114 int rv = pthread_cond_timedwait_monotonic_np( |
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 // On failure, we only expect the CV to timeout. Any other error value means |
| 122 // that we've unexpectedly woken up. |
121 DCHECK(rv == 0 || rv == ETIMEDOUT); | 123 DCHECK(rv == 0 || rv == ETIMEDOUT); |
122 #if DCHECK_IS_ON() | 124 #if DCHECK_IS_ON() |
123 user_lock_->CheckUnheldAndMark(); | 125 user_lock_->CheckUnheldAndMark(); |
124 #endif | 126 #endif |
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 |