Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1063)

Unified Diff: runtime/vm/thread_linux.cc

Issue 8463032: Wait on the monotonic clock to guard against changes to the system clock. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/globals.h ('k') | runtime/vm/vm.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/thread_linux.cc
diff --git a/runtime/vm/thread_linux.cc b/runtime/vm/thread_linux.cc
index ef653c735e384dc908727cced86d14a3a2c4cc3d..faf445fba7013fac0125427467f2eac249aedb90 100644
--- a/runtime/vm/thread_linux.cc
+++ b/runtime/vm/thread_linux.cc
@@ -18,18 +18,17 @@ 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;
- 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 secs = millis / kMillisecondsPerSecond;
+ int64_t nanos =
+ (millis - (secs * kMillisecondsPerSecond)) * kNanosecondsPerMillisecond;
+ 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 >= kNanosecondsPerSecond) {
+ ts->tv_sec += 1;
+ ts->tv_nsec -= kNanosecondsPerSecond;
+ }
}
@@ -162,22 +161,32 @@ void Mutex::Unlock() {
Monitor::Monitor() {
- pthread_mutexattr_t attr;
- int result = pthread_mutexattr_init(&attr);
+ pthread_mutexattr_t mutex_attr;
+ int result = pthread_mutexattr_init(&mutex_attr);
VALIDATE_PTHREAD_RESULT(result);
#if defined(DEBUG)
- result = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
+ result = pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_ERRORCHECK);
VALIDATE_PTHREAD_RESULT(result);
#endif // defined(DEBUG)
- result = pthread_mutex_init(data_.mutex(), &attr);
+ result = pthread_mutex_init(data_.mutex(), &mutex_attr);
VALIDATE_PTHREAD_RESULT(result);
- result = pthread_mutexattr_destroy(&attr);
+ result = pthread_mutexattr_destroy(&mutex_attr);
+ VALIDATE_PTHREAD_RESULT(result);
+
+ pthread_condattr_t cond_attr;
+ result = pthread_condattr_init(&cond_attr);
+ VALIDATE_PTHREAD_RESULT(result);
+
+ result = pthread_condattr_setclock(&cond_attr, CLOCK_MONOTONIC);
+ VALIDATE_PTHREAD_RESULT(result);
+
+ result = pthread_cond_init(data_.cond(), &cond_attr);
VALIDATE_PTHREAD_RESULT(result);
- result = pthread_cond_init(data_.cond(), NULL);
+ result = pthread_condattr_destroy(&cond_attr);
VALIDATE_PTHREAD_RESULT(result);
}
« no previous file with comments | « runtime/vm/globals.h ('k') | runtime/vm/vm.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698