OLD | NEW |
---|---|
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/base/platform/time.h" | 5 #include "src/base/platform/time.h" |
6 | 6 |
7 #if V8_OS_POSIX | 7 #if V8_OS_POSIX |
8 #include <fcntl.h> // for O_RDONLY | 8 #include <fcntl.h> // for O_RDONLY |
9 #include <sys/time.h> | 9 #include <sys/time.h> |
10 #include <unistd.h> | 10 #include <unistd.h> |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
245 } | 245 } |
246 uint64_t us = static_cast<uint64_t>(us_ + kTimeToEpochInMicroseconds) * 10; | 246 uint64_t us = static_cast<uint64_t>(us_ + kTimeToEpochInMicroseconds) * 10; |
247 ft.dwLowDateTime = static_cast<DWORD>(us); | 247 ft.dwLowDateTime = static_cast<DWORD>(us); |
248 ft.dwHighDateTime = static_cast<DWORD>(us >> 32); | 248 ft.dwHighDateTime = static_cast<DWORD>(us >> 32); |
249 return ft; | 249 return ft; |
250 } | 250 } |
251 | 251 |
252 #elif V8_OS_POSIX | 252 #elif V8_OS_POSIX |
253 | 253 |
254 Time Time::Now() { | 254 Time Time::Now() { |
255 #if V8_OS_LINUX | |
Benedikt Meurer
2015/05/06 09:40:34
How about using #ifdef CLOCK_REALTIME_COARSE here?
| |
256 struct timespec ts; | |
257 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
| |
258 if (clock_id == -1) { | |
259 // CLOCK_REALTIME_COARSE is not supported on kernels <= 2.6.31. | |
260 // Probe the kernel to see if it's available and has <= 1 ms resolution. | |
261 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
| |
262 if (-1 == clock_getres(kClockRealTimeCoarse, &ts) || | |
263 ts.tv_nsec > 1000 * 1000 || ts.tv_sec > 0) { | |
264 clock_id = CLOCK_REALTIME; // Not available or not suitable. | |
265 } else { | |
266 clock_id = kClockRealTimeCoarse; | |
Dean McNamee
2015/05/06 09:09:34
I would make a note, if possible, about what the d
| |
267 } | |
268 } | |
269 int result = clock_gettime(clock_id, &ts); | |
270 DCHECK_EQ(0, result); | |
271 USE(result); | |
272 return FromTimespec(ts); | |
273 #else | |
255 struct timeval tv; | 274 struct timeval tv; |
256 int result = gettimeofday(&tv, NULL); | 275 int result = gettimeofday(&tv, NULL); |
257 DCHECK_EQ(0, result); | 276 DCHECK_EQ(0, result); |
258 USE(result); | 277 USE(result); |
259 return FromTimeval(tv); | 278 return FromTimeval(tv); |
279 #endif | |
260 } | 280 } |
261 | 281 |
262 | 282 |
263 Time Time::NowFromSystemTime() { | 283 Time Time::NowFromSystemTime() { |
264 return Now(); | 284 return Now(); |
265 } | 285 } |
266 | 286 |
267 | 287 |
268 Time Time::FromTimespec(struct timespec ts) { | 288 Time Time::FromTimespec(struct timespec ts) { |
269 DCHECK(ts.tv_nsec >= 0); | 289 DCHECK(ts.tv_nsec >= 0); |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
638 | 658 |
639 | 659 |
640 // static | 660 // static |
641 bool TimeTicks::KernelTimestampAvailable() { | 661 bool TimeTicks::KernelTimestampAvailable() { |
642 return kernel_tick_clock.Pointer()->Available(); | 662 return kernel_tick_clock.Pointer()->Available(); |
643 } | 663 } |
644 | 664 |
645 #endif // V8_OS_WIN | 665 #endif // V8_OS_WIN |
646 | 666 |
647 } } // namespace v8::base | 667 } } // namespace v8::base |
OLD | NEW |