| 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 <sys/errno.h> | 7 #include <sys/errno.h> |
| 8 | 8 |
| 9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
| 10 | 10 |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 | 221 |
| 222 Monitor::WaitResult Monitor::Wait(int64_t millis) { | 222 Monitor::WaitResult Monitor::Wait(int64_t millis) { |
| 223 // TODO(iposva): Do we need to track lock owners? | 223 // TODO(iposva): Do we need to track lock owners? |
| 224 Monitor::WaitResult retval = kNotified; | 224 Monitor::WaitResult retval = kNotified; |
| 225 if (millis == 0) { | 225 if (millis == 0) { |
| 226 // Wait forever. | 226 // Wait forever. |
| 227 int result = pthread_cond_wait(data_.cond(), data_.mutex()); | 227 int result = pthread_cond_wait(data_.cond(), data_.mutex()); |
| 228 VALIDATE_PTHREAD_RESULT(result); | 228 VALIDATE_PTHREAD_RESULT(result); |
| 229 } else { | 229 } else { |
| 230 struct timespec ts; | 230 struct timespec ts; |
| 231 int64_t secs = millis / 1000; | 231 int64_t secs = millis / kMillisecondsPerSecond; |
| 232 int64_t nanos = (millis - (secs * 1000)) * 1000000; | 232 int64_t nanos = (millis - (secs * kMillisecondsPerSecond)) * |
| 233 kNanosecondsPerMillisecond; |
| 233 ts.tv_sec = secs; | 234 ts.tv_sec = secs; |
| 234 ts.tv_nsec = nanos; | 235 ts.tv_nsec = nanos; |
| 235 int result = pthread_cond_timedwait_relative_np(data_.cond(), | 236 int result = pthread_cond_timedwait_relative_np(data_.cond(), |
| 236 data_.mutex(), | 237 data_.mutex(), |
| 237 &ts); | 238 &ts); |
| 238 ASSERT((result == 0) || (result == ETIMEDOUT)); | 239 ASSERT((result == 0) || (result == ETIMEDOUT)); |
| 239 if (result == ETIMEDOUT) { | 240 if (result == ETIMEDOUT) { |
| 240 retval = kTimedOut; | 241 retval = kTimedOut; |
| 241 } | 242 } |
| 242 } | 243 } |
| 243 return retval; | 244 return retval; |
| 244 } | 245 } |
| 245 | 246 |
| 246 | 247 |
| 247 void Monitor::Notify() { | 248 void Monitor::Notify() { |
| 248 // TODO(iposva): Do we need to track lock owners? | 249 // TODO(iposva): Do we need to track lock owners? |
| 249 int result = pthread_cond_signal(data_.cond()); | 250 int result = pthread_cond_signal(data_.cond()); |
| 250 VALIDATE_PTHREAD_RESULT(result); | 251 VALIDATE_PTHREAD_RESULT(result); |
| 251 } | 252 } |
| 252 | 253 |
| 253 | 254 |
| 254 void Monitor::NotifyAll() { | 255 void Monitor::NotifyAll() { |
| 255 // TODO(iposva): Do we need to track lock owners? | 256 // TODO(iposva): Do we need to track lock owners? |
| 256 int result = pthread_cond_broadcast(data_.cond()); | 257 int result = pthread_cond_broadcast(data_.cond()); |
| 257 VALIDATE_PTHREAD_RESULT(result); | 258 VALIDATE_PTHREAD_RESULT(result); |
| 258 } | 259 } |
| 259 | 260 |
| 260 } // namespace dart | 261 } // namespace dart |
| OLD | NEW |