Chromium Code Reviews| 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 |
| } |