Chromium Code Reviews| Index: runtime/vm/thread_linux.cc |
| diff --git a/runtime/vm/thread_linux.cc b/runtime/vm/thread_linux.cc |
| index ef653c735e384dc908727cced86d14a3a2c4cc3d..98b1c66a2a954ca123b336a9b859f0cbfca9468f 100644 |
| --- a/runtime/vm/thread_linux.cc |
| +++ b/runtime/vm/thread_linux.cc |
| @@ -18,18 +18,16 @@ namespace dart { |
| static void ComputeTimeSpec(struct timespec* ts, int64_t millis) { |
| - struct timeval time; |
| - struct timeval delta; |
| - // Convert the millis to a timeval delta. |
| int64_t secs = millis / 1000; |
|
siva
2011/11/14 18:32:28
Maybe we should have 3 constants to make this more
cshapiro
2011/11/14 22:24:25
Good idea. I have added to globals.h time constan
|
| - int64_t micros = (millis - (secs * 1000)) * 1000; |
| - delta.tv_sec = secs; |
| - delta.tv_usec = micros; |
| - // Get the current time and add the delta. Convert the result to a timespec. |
| - int result = gettimeofday(&time, NULL); |
| + int64_t nanos = (millis - (secs * 1000)) * 1000 * 1000; |
| + int result = clock_gettime(CLOCK_MONOTONIC, ts); |
| ASSERT(result == 0); |
| - timeradd(&time, &delta, &time); |
| - TIMEVAL_TO_TIMESPEC(&time, ts); |
| + ts->tv_sec += secs; |
| + ts->tv_nsec += nanos; |
| + if (ts->tv_nsec >= (1000 * 1000 * 1000)) { |
| + ts->tv_sec += 1; |
| + ts->tv_nsec -= (1000 * 1000 * 1000); |
| + } |
| } |
| @@ -162,23 +160,37 @@ void Mutex::Unlock() { |
| Monitor::Monitor() { |
| - pthread_mutexattr_t attr; |
| - int result = pthread_mutexattr_init(&attr); |
| - VALIDATE_PTHREAD_RESULT(result); |
| + { |
|
siva
2011/11/14 18:32:28
The scoping feels weird why not just name the vari
cshapiro
2011/11/14 22:24:25
Yeah, in fact, I wrote it that way originally. Re
|
| + pthread_mutexattr_t attr; |
| + int result = pthread_mutexattr_init(&attr); |
| + VALIDATE_PTHREAD_RESULT(result); |
| #if defined(DEBUG) |
| - result = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK); |
| - VALIDATE_PTHREAD_RESULT(result); |
| + result = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK); |
| + VALIDATE_PTHREAD_RESULT(result); |
| #endif // defined(DEBUG) |
| - result = pthread_mutex_init(data_.mutex(), &attr); |
| - VALIDATE_PTHREAD_RESULT(result); |
| + result = pthread_mutex_init(data_.mutex(), &attr); |
| + VALIDATE_PTHREAD_RESULT(result); |
| - result = pthread_mutexattr_destroy(&attr); |
| - VALIDATE_PTHREAD_RESULT(result); |
| + result = pthread_mutexattr_destroy(&attr); |
| + VALIDATE_PTHREAD_RESULT(result); |
| + } |
| - result = pthread_cond_init(data_.cond(), NULL); |
| - VALIDATE_PTHREAD_RESULT(result); |
| + { |
| + pthread_condattr_t attr; |
| + int result = pthread_condattr_init(&attr); |
| + VALIDATE_PTHREAD_RESULT(result); |
| + |
| + result = pthread_condattr_setclock(&attr, CLOCK_MONOTONIC); |
| + VALIDATE_PTHREAD_RESULT(result); |
| + |
| + result = pthread_cond_init(data_.cond(), &attr); |
| + VALIDATE_PTHREAD_RESULT(result); |
| + |
| + result = pthread_condattr_destroy(&attr); |
| + VALIDATE_PTHREAD_RESULT(result); |
| + } |
| } |