OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include <sys/errno.h> | 5 #include <sys/errno.h> |
6 | 6 |
7 #include "vm/thread.h" | 7 #include "vm/thread.h" |
8 | 8 |
9 #include "vm/assert.h" | 9 #include "vm/assert.h" |
10 | 10 |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 int result = pthread_mutex_unlock(data_.mutex()); | 186 int result = pthread_mutex_unlock(data_.mutex()); |
187 VALIDATE_PTHREAD_RESULT(result); | 187 VALIDATE_PTHREAD_RESULT(result); |
188 } | 188 } |
189 | 189 |
190 | 190 |
191 Monitor::WaitResult Monitor::Wait(int64_t millis) { | 191 Monitor::WaitResult Monitor::Wait(int64_t millis) { |
192 // TODO(iposva): Do we need to track lock owners? | 192 // TODO(iposva): Do we need to track lock owners? |
193 Monitor::WaitResult retval = kNotified; | 193 Monitor::WaitResult retval = kNotified; |
194 if (millis == 0) { | 194 if (millis == 0) { |
195 // Wait forever. | 195 // Wait forever. |
| 196 // If the thread receives a signal, pthread_cond_wait may return 0, |
| 197 // because of a spurious wakeup. |
196 int result = pthread_cond_wait(data_.cond(), data_.mutex()); | 198 int result = pthread_cond_wait(data_.cond(), data_.mutex()); |
197 VALIDATE_PTHREAD_RESULT(result); | 199 VALIDATE_PTHREAD_RESULT(result); |
198 } else { | 200 } else { |
199 struct timespec ts; | 201 struct timespec ts; |
200 int64_t secs = millis / 1000; | 202 int64_t secs = millis / 1000; |
201 int64_t nanos = (millis - (secs * 1000)) * 1000000; | 203 int64_t nanos = (millis - (secs * 1000)) * 1000000; |
202 ts.tv_sec = secs; | 204 ts.tv_sec = secs; |
203 ts.tv_nsec = nanos; | 205 ts.tv_nsec = nanos; |
204 int result = pthread_cond_timedwait_relative_np(data_.cond(), | 206 int result = pthread_cond_timedwait_relative_np(data_.cond(), |
205 data_.mutex(), | 207 data_.mutex(), |
(...skipping 14 matching lines...) Expand all Loading... |
220 } | 222 } |
221 | 223 |
222 | 224 |
223 void Monitor::NotifyAll() { | 225 void Monitor::NotifyAll() { |
224 // TODO(iposva): Do we need to track lock owners? | 226 // TODO(iposva): Do we need to track lock owners? |
225 int result = pthread_cond_broadcast(data_.cond()); | 227 int result = pthread_cond_broadcast(data_.cond()); |
226 VALIDATE_PTHREAD_RESULT(result); | 228 VALIDATE_PTHREAD_RESULT(result); |
227 } | 229 } |
228 | 230 |
229 } // namespace dart | 231 } // namespace dart |
OLD | NEW |