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. | |
198 int result = pthread_cond_wait(data_.cond(), data_.mutex()); | 196 int result = pthread_cond_wait(data_.cond(), data_.mutex()); |
199 VALIDATE_PTHREAD_RESULT(result); | 197 VALIDATE_PTHREAD_RESULT(result); |
200 } else { | 198 } else { |
201 struct timespec ts; | 199 struct timespec ts; |
202 int64_t secs = millis / 1000; | 200 int64_t secs = millis / 1000; |
203 int64_t nanos = (millis - (secs * 1000)) * 1000000; | 201 int64_t nanos = (millis - (secs * 1000)) * 1000000; |
204 ts.tv_sec = secs; | 202 ts.tv_sec = secs; |
205 ts.tv_nsec = nanos; | 203 ts.tv_nsec = nanos; |
206 int result = pthread_cond_timedwait_relative_np(data_.cond(), | 204 int result = pthread_cond_timedwait_relative_np(data_.cond(), |
207 data_.mutex(), | 205 data_.mutex(), |
(...skipping 14 matching lines...) Expand all Loading... |
222 } | 220 } |
223 | 221 |
224 | 222 |
225 void Monitor::NotifyAll() { | 223 void Monitor::NotifyAll() { |
226 // TODO(iposva): Do we need to track lock owners? | 224 // TODO(iposva): Do we need to track lock owners? |
227 int result = pthread_cond_broadcast(data_.cond()); | 225 int result = pthread_cond_broadcast(data_.cond()); |
228 VALIDATE_PTHREAD_RESULT(result); | 226 VALIDATE_PTHREAD_RESULT(result); |
229 } | 227 } |
230 | 228 |
231 } // namespace dart | 229 } // namespace dart |
OLD | NEW |