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

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: 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 | « no previous file | 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..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);
+ }
}
« no previous file with comments | « no previous file | runtime/vm/vm.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698