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 <sys/time.h> | 8 #include <sys/time.h> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 24 matching lines...) Expand all Loading... | |
35 pthread_condattr_setclock(&attrs, CLOCK_MONOTONIC); | 35 pthread_condattr_setclock(&attrs, CLOCK_MONOTONIC); |
36 rv = pthread_cond_init(&condition_, &attrs); | 36 rv = pthread_cond_init(&condition_, &attrs); |
37 pthread_condattr_destroy(&attrs); | 37 pthread_condattr_destroy(&attrs); |
38 #else | 38 #else |
39 rv = pthread_cond_init(&condition_, NULL); | 39 rv = pthread_cond_init(&condition_, NULL); |
40 #endif | 40 #endif |
41 DCHECK_EQ(0, rv); | 41 DCHECK_EQ(0, rv); |
42 } | 42 } |
43 | 43 |
44 ConditionVariable::~ConditionVariable() { | 44 ConditionVariable::~ConditionVariable() { |
45 #if defined(OS_MACOSX) | |
46 // This hack is necessary to avoid a fatal pthreads subsystem bug in the | |
47 // Darwin kernel. http://crbug.com/517681. | |
48 { | |
Mark Mentovai
2015/09/04 12:30:56
The bug says 10.10 and 10.11. Does this happen on
erikchen
2015/09/04 17:25:37
It does - the comment was looking only at the most
| |
49 base::Lock lock; | |
Mark Mentovai
2015/09/04 12:30:56
How do we know that the memory used for this mutex
erikchen
2015/09/04 17:25:37
We could, soon after each new thread is created, m
| |
50 base::AutoLock l(lock); | |
51 struct timespec ts; | |
52 ts.tv_sec = 0; | |
53 ts.tv_nsec = 1; | |
54 pthread_cond_timedwait_relative_np(&condition_, lock.lock_.native_handle(), | |
55 &ts); | |
56 } | |
57 #endif | |
58 | |
45 int rv = pthread_cond_destroy(&condition_); | 59 int rv = pthread_cond_destroy(&condition_); |
46 DCHECK_EQ(0, rv); | 60 DCHECK_EQ(0, rv); |
47 } | 61 } |
48 | 62 |
49 void ConditionVariable::Wait() { | 63 void ConditionVariable::Wait() { |
50 base::ThreadRestrictions::AssertWaitAllowed(); | 64 base::ThreadRestrictions::AssertWaitAllowed(); |
51 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) | 65 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) |
52 user_lock_->CheckHeldAndUnmark(); | 66 user_lock_->CheckHeldAndUnmark(); |
53 #endif | 67 #endif |
54 int rv = pthread_cond_wait(&condition_, user_mutex_); | 68 int rv = pthread_cond_wait(&condition_, user_mutex_); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 int rv = pthread_cond_broadcast(&condition_); | 127 int rv = pthread_cond_broadcast(&condition_); |
114 DCHECK_EQ(0, rv); | 128 DCHECK_EQ(0, rv); |
115 } | 129 } |
116 | 130 |
117 void ConditionVariable::Signal() { | 131 void ConditionVariable::Signal() { |
118 int rv = pthread_cond_signal(&condition_); | 132 int rv = pthread_cond_signal(&condition_); |
119 DCHECK_EQ(0, rv); | 133 DCHECK_EQ(0, rv); |
120 } | 134 } |
121 | 135 |
122 } // namespace base | 136 } // namespace base |
OLD | NEW |