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/globals.h" | 5 #include "platform/globals.h" |
6 #if defined(TARGET_OS_MACOS) | 6 #if defined(TARGET_OS_MACOS) |
7 | 7 |
8 #include "platform/thread.h" | 8 #include "platform/thread.h" |
9 | 9 |
10 #include <sys/errno.h> // NOLINT | 10 #include <sys/errno.h> // NOLINT |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 Monitor::WaitResult Monitor::WaitMicros(int64_t micros) { | 290 Monitor::WaitResult Monitor::WaitMicros(int64_t micros) { |
291 // TODO(iposva): Do we need to track lock owners? | 291 // TODO(iposva): Do we need to track lock owners? |
292 Monitor::WaitResult retval = kNotified; | 292 Monitor::WaitResult retval = kNotified; |
293 if (micros == kNoTimeout) { | 293 if (micros == kNoTimeout) { |
294 // Wait forever. | 294 // Wait forever. |
295 int result = pthread_cond_wait(data_.cond(), data_.mutex()); | 295 int result = pthread_cond_wait(data_.cond(), data_.mutex()); |
296 VALIDATE_PTHREAD_RESULT(result); | 296 VALIDATE_PTHREAD_RESULT(result); |
297 } else { | 297 } else { |
298 struct timespec ts; | 298 struct timespec ts; |
299 int64_t secs = micros / kMicrosecondsPerSecond; | 299 int64_t secs = micros / kMicrosecondsPerSecond; |
| 300 if (secs > kMaxInt32) { |
| 301 // Avoid truncation of overly large timeout values. |
| 302 secs = kMaxInt32; |
| 303 } |
300 int64_t nanos = | 304 int64_t nanos = |
301 (micros - (secs * kMicrosecondsPerSecond)) * kNanosecondsPerMicrosecond; | 305 (micros - (secs * kMicrosecondsPerSecond)) * kNanosecondsPerMicrosecond; |
302 ts.tv_sec = secs; | 306 ts.tv_sec = static_cast<int32_t>(secs); |
303 ts.tv_nsec = nanos; | 307 ts.tv_nsec = static_cast<long>(nanos); // NOLINT (long used in timespec). |
304 int result = pthread_cond_timedwait_relative_np(data_.cond(), | 308 int result = pthread_cond_timedwait_relative_np(data_.cond(), |
305 data_.mutex(), | 309 data_.mutex(), |
306 &ts); | 310 &ts); |
307 ASSERT((result == 0) || (result == ETIMEDOUT)); | 311 ASSERT((result == 0) || (result == ETIMEDOUT)); |
308 if (result == ETIMEDOUT) { | 312 if (result == ETIMEDOUT) { |
309 retval = kTimedOut; | 313 retval = kTimedOut; |
310 } | 314 } |
311 } | 315 } |
312 return retval; | 316 return retval; |
313 } | 317 } |
314 | 318 |
315 | 319 |
316 void Monitor::Notify() { | 320 void Monitor::Notify() { |
317 // TODO(iposva): Do we need to track lock owners? | 321 // TODO(iposva): Do we need to track lock owners? |
318 int result = pthread_cond_signal(data_.cond()); | 322 int result = pthread_cond_signal(data_.cond()); |
319 VALIDATE_PTHREAD_RESULT(result); | 323 VALIDATE_PTHREAD_RESULT(result); |
320 } | 324 } |
321 | 325 |
322 | 326 |
323 void Monitor::NotifyAll() { | 327 void Monitor::NotifyAll() { |
324 // TODO(iposva): Do we need to track lock owners? | 328 // TODO(iposva): Do we need to track lock owners? |
325 int result = pthread_cond_broadcast(data_.cond()); | 329 int result = pthread_cond_broadcast(data_.cond()); |
326 VALIDATE_PTHREAD_RESULT(result); | 330 VALIDATE_PTHREAD_RESULT(result); |
327 } | 331 } |
328 | 332 |
329 } // namespace dart | 333 } // namespace dart |
330 | 334 |
331 #endif // defined(TARGET_OS_MACOS) | 335 #endif // defined(TARGET_OS_MACOS) |
OLD | NEW |