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

Unified Diff: src/platform/time.cc

Issue 70133003: CLOCK_REALTIME is 0 on Linux, use -1 for invalid clock id. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/platform/time.cc
diff --git a/src/platform/time.cc b/src/platform/time.cc
index d87dc24a65619df2e5a3adca6b94f4dc9df87b18..eb5d72fdb12e2572a2b28911ad02b23e9fc40b85 100644
--- a/src/platform/time.cc
+++ b/src/platform/time.cc
@@ -295,8 +295,10 @@ Time Time::Now() {
struct timespec ts;
// Use CLOCK_REALTIME_COARSE if it's available and has a precision of 1ms
// or higher. It's serviced from the vDSO with no system call overhead.
- static clock_t clock_id = static_cast<clock_t>(0);
- if (!clock_id) {
+ static clock_t clock_id = static_cast<clock_t>(-1);
+ STATIC_ASSERT(CLOCK_REALTIME != static_cast<clock_t>(-1));
+ STATIC_ASSERT(CLOCK_REALTIME_COARSE != static_cast<clock_t>(-1));
+ if (clock_id == static_cast<clock_t>(-1)) {
if (clock_getres(CLOCK_REALTIME_COARSE, &ts) == 0
&& ts.tv_nsec <= kNanosecondsPerMillisecond)
clock_id = CLOCK_REALTIME_COARSE;
@@ -611,8 +613,10 @@ TimeTicks TimeTicks::HighResolutionNow() {
#if defined(CLOCK_MONOTONIC_COARSE)
// Use CLOCK_MONOTONIC_COARSE if it's available and has a precision of 1ms
// or higher. It's serviced from the vDSO with no system call overhead.
- static clock_t clock_id = static_cast<clock_t>(0);
- if (!clock_id) {
+ static clock_t clock_id = static_cast<clock_t>(-1);
+ STATIC_ASSERT(CLOCK_MONOTONIC != static_cast<clock_t>(-1));
+ STATIC_ASSERT(CLOCK_MONOTONIC_COARSE != static_cast<clock_t>(-1));
+ if (clock_id == static_cast<clock_t>(-1)) {
if (clock_getres(CLOCK_MONOTONIC_COARSE, &ts) == 0
&& ts.tv_nsec <= Time::kNanosecondsPerMillisecond)
clock_id = CLOCK_MONOTONIC_COARSE;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698