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

Unified Diff: src/base/platform/time.cc

Issue 1125003002: Use CLOCK_REALTIME_COARSE when available. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 7 months 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/base/platform/time.cc
diff --git a/src/base/platform/time.cc b/src/base/platform/time.cc
index b6a11cff34f313661536eb0d20b43cf7d598e479..ad60270d47954e71806cdd1bee353a2f9ea77c2c 100644
--- a/src/base/platform/time.cc
+++ b/src/base/platform/time.cc
@@ -252,11 +252,31 @@ FILETIME Time::ToFiletime() const {
#elif V8_OS_POSIX
Time Time::Now() {
+#if V8_OS_LINUX
Benedikt Meurer 2015/05/06 09:40:34 How about using #ifdef CLOCK_REALTIME_COARSE here?
+ struct timespec ts;
+ static clockid_t clock_id = -1;
Dean McNamee 2015/05/06 09:09:34 I would maybe make a note that clockid_t is define
+ if (clock_id == -1) {
+ // CLOCK_REALTIME_COARSE is not supported on kernels <= 2.6.31.
+ // Probe the kernel to see if it's available and has <= 1 ms resolution.
+ static const clockid_t kClockRealTimeCoarse = 5;
Dean McNamee 2015/05/06 09:09:34 Is there a reason you can't use the CLOCK_REALTIME
+ if (-1 == clock_getres(kClockRealTimeCoarse, &ts) ||
+ ts.tv_nsec > 1000 * 1000 || ts.tv_sec > 0) {
+ clock_id = CLOCK_REALTIME; // Not available or not suitable.
+ } else {
+ clock_id = kClockRealTimeCoarse;
Dean McNamee 2015/05/06 09:09:34 I would make a note, if possible, about what the d
+ }
+ }
+ int result = clock_gettime(clock_id, &ts);
+ DCHECK_EQ(0, result);
+ USE(result);
+ return FromTimespec(ts);
+#else
struct timeval tv;
int result = gettimeofday(&tv, NULL);
DCHECK_EQ(0, result);
USE(result);
return FromTimeval(tv);
+#endif
}
« 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