| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 "platform/thread.h" | 5 #include "platform/thread.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 "platform/assert.h" | 10 #include "platform/assert.h" |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 result = pthread_mutex_init(data_.mutex(), &mutex_attr); | 204 result = pthread_mutex_init(data_.mutex(), &mutex_attr); |
| 205 VALIDATE_PTHREAD_RESULT(result); | 205 VALIDATE_PTHREAD_RESULT(result); |
| 206 | 206 |
| 207 result = pthread_mutexattr_destroy(&mutex_attr); | 207 result = pthread_mutexattr_destroy(&mutex_attr); |
| 208 VALIDATE_PTHREAD_RESULT(result); | 208 VALIDATE_PTHREAD_RESULT(result); |
| 209 | 209 |
| 210 pthread_condattr_t cond_attr; | 210 pthread_condattr_t cond_attr; |
| 211 result = pthread_condattr_init(&cond_attr); | 211 result = pthread_condattr_init(&cond_attr); |
| 212 VALIDATE_PTHREAD_RESULT(result); | 212 VALIDATE_PTHREAD_RESULT(result); |
| 213 | 213 |
| 214 result = pthread_condattr_setclock(&cond_attr, CLOCK_MONOTONIC); | |
| 215 VALIDATE_PTHREAD_RESULT(result); | |
| 216 | |
| 217 result = pthread_cond_init(data_.cond(), &cond_attr); | 214 result = pthread_cond_init(data_.cond(), &cond_attr); |
| 218 VALIDATE_PTHREAD_RESULT(result); | 215 VALIDATE_PTHREAD_RESULT(result); |
| 219 | 216 |
| 220 result = pthread_condattr_destroy(&cond_attr); | 217 result = pthread_condattr_destroy(&cond_attr); |
| 221 VALIDATE_PTHREAD_RESULT(result); | 218 VALIDATE_PTHREAD_RESULT(result); |
| 222 } | 219 } |
| 223 | 220 |
| 224 | 221 |
| 225 Monitor::~Monitor() { | 222 Monitor::~Monitor() { |
| 226 int result = pthread_mutex_destroy(data_.mutex()); | 223 int result = pthread_mutex_destroy(data_.mutex()); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 248 Monitor::WaitResult Monitor::Wait(int64_t millis) { | 245 Monitor::WaitResult Monitor::Wait(int64_t millis) { |
| 249 // TODO(iposva): Do we need to track lock owners? | 246 // TODO(iposva): Do we need to track lock owners? |
| 250 Monitor::WaitResult retval = kNotified; | 247 Monitor::WaitResult retval = kNotified; |
| 251 if (millis == 0) { | 248 if (millis == 0) { |
| 252 // Wait forever. | 249 // Wait forever. |
| 253 int result = pthread_cond_wait(data_.cond(), data_.mutex()); | 250 int result = pthread_cond_wait(data_.cond(), data_.mutex()); |
| 254 VALIDATE_PTHREAD_RESULT(result); | 251 VALIDATE_PTHREAD_RESULT(result); |
| 255 } else { | 252 } else { |
| 256 struct timespec ts; | 253 struct timespec ts; |
| 257 ComputeTimeSpec(&ts, millis); | 254 ComputeTimeSpec(&ts, millis); |
| 258 int result = pthread_cond_timedwait(data_.cond(), data_.mutex(), &ts); | 255 int result = pthread_cond_timedwait_monotonic( |
| 256 data_.cond(), data_.mutex(), &ts); |
| 259 ASSERT((result == 0) || (result == ETIMEDOUT)); | 257 ASSERT((result == 0) || (result == ETIMEDOUT)); |
| 260 if (result == ETIMEDOUT) { | 258 if (result == ETIMEDOUT) { |
| 261 retval = kTimedOut; | 259 retval = kTimedOut; |
| 262 } | 260 } |
| 263 } | 261 } |
| 264 return retval; | 262 return retval; |
| 265 } | 263 } |
| 266 | 264 |
| 267 | 265 |
| 268 void Monitor::Notify() { | 266 void Monitor::Notify() { |
| 269 // TODO(iposva): Do we need to track lock owners? | 267 // TODO(iposva): Do we need to track lock owners? |
| 270 int result = pthread_cond_signal(data_.cond()); | 268 int result = pthread_cond_signal(data_.cond()); |
| 271 VALIDATE_PTHREAD_RESULT(result); | 269 VALIDATE_PTHREAD_RESULT(result); |
| 272 } | 270 } |
| 273 | 271 |
| 274 | 272 |
| 275 void Monitor::NotifyAll() { | 273 void Monitor::NotifyAll() { |
| 276 // TODO(iposva): Do we need to track lock owners? | 274 // TODO(iposva): Do we need to track lock owners? |
| 277 int result = pthread_cond_broadcast(data_.cond()); | 275 int result = pthread_cond_broadcast(data_.cond()); |
| 278 VALIDATE_PTHREAD_RESULT(result); | 276 VALIDATE_PTHREAD_RESULT(result); |
| 279 } | 277 } |
| 280 | 278 |
| 281 } // namespace dart | 279 } // namespace dart |
| OLD | NEW |