Chromium Code Reviews| 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/platform/time.h" | 5 #include "src/platform/time.h" |
| 6 | 6 |
| 7 #if V8_OS_POSIX | 7 #if V8_OS_POSIX |
| 8 #include <sys/time.h> | 8 #include <sys/time.h> |
| 9 #endif | 9 #endif |
| 10 #if V8_OS_MACOSX | 10 #if V8_OS_MACOSX |
| 11 #include <mach/mach_time.h> | 11 #include <mach/mach_time.h> |
| 12 #endif | 12 #endif |
| 13 | 13 |
| 14 #include <string.h> | 14 #include <string.h> |
| 15 | 15 |
| 16 #include "src/checks.h" | 16 #include "src/checks.h" |
| 17 #include "src/cpu.h" | 17 #include "src/cpu.h" |
| 18 #include "src/platform.h" | 18 #include "src/platform.h" |
| 19 #if V8_OS_WIN | 19 #if V8_OS_WIN |
| 20 #include "src/win32-headers.h" | 20 #include "src/base/win32-headers.h" |
| 21 #endif | 21 #endif |
| 22 | 22 |
| 23 namespace v8 { | 23 namespace v8 { |
| 24 namespace internal { | 24 namespace internal { |
| 25 | 25 |
| 26 TimeDelta TimeDelta::FromDays(int days) { | 26 TimeDelta TimeDelta::FromDays(int days) { |
| 27 return TimeDelta(days * Time::kMicrosecondsPerDay); | 27 return TimeDelta(days * Time::kMicrosecondsPerDay); |
| 28 } | 28 } |
| 29 | 29 |
| 30 | 30 |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 ::GetSystemTimeAsFileTime(&ft); | 186 ::GetSystemTimeAsFileTime(&ft); |
| 187 return Time::FromFiletime(ft); | 187 return Time::FromFiletime(ft); |
| 188 } | 188 } |
| 189 | 189 |
| 190 TimeTicks initial_ticks_; | 190 TimeTicks initial_ticks_; |
| 191 Time initial_time_; | 191 Time initial_time_; |
| 192 Mutex mutex_; | 192 Mutex mutex_; |
| 193 }; | 193 }; |
| 194 | 194 |
| 195 | 195 |
| 196 static LazyStaticInstance<Clock, | 196 static base::LazyStaticInstance<Clock, base::DefaultConstructTrait<Clock>, |
|
Jakob Kummerow
2014/06/05 11:49:06
IWYU?
| |
| 197 DefaultConstructTrait<Clock>, | 197 base::ThreadSafeInitOnceTrait>::type clock = |
| 198 ThreadSafeInitOnceTrait>::type clock = LAZY_STATIC_INSTANCE_INITIALIZER; | 198 LAZY_STATIC_INSTANCE_INITIALIZER; |
| 199 | 199 |
| 200 | 200 |
| 201 Time Time::Now() { | 201 Time Time::Now() { |
| 202 return clock.Pointer()->Now(); | 202 return clock.Pointer()->Now(); |
| 203 } | 203 } |
| 204 | 204 |
| 205 | 205 |
| 206 Time Time::NowFromSystemTime() { | 206 Time Time::NowFromSystemTime() { |
| 207 return clock.Pointer()->NowFromSystemTime(); | 207 return clock.Pointer()->NowFromSystemTime(); |
| 208 } | 208 } |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 455 return false; | 455 return false; |
| 456 } | 456 } |
| 457 | 457 |
| 458 private: | 458 private: |
| 459 Mutex mutex_; | 459 Mutex mutex_; |
| 460 DWORD last_seen_now_; | 460 DWORD last_seen_now_; |
| 461 int64_t rollover_ms_; | 461 int64_t rollover_ms_; |
| 462 }; | 462 }; |
| 463 | 463 |
| 464 | 464 |
| 465 static LazyStaticInstance<RolloverProtectedTickClock, | 465 static base::LazyStaticInstance< |
| 466 DefaultConstructTrait<RolloverProtectedTickClock>, | 466 RolloverProtectedTickClock, |
| 467 ThreadSafeInitOnceTrait>::type tick_clock = | 467 base::DefaultConstructTrait<RolloverProtectedTickClock>, |
| 468 LAZY_STATIC_INSTANCE_INITIALIZER; | 468 base::ThreadSafeInitOnceTrait>::type tick_clock = |
| 469 LAZY_STATIC_INSTANCE_INITIALIZER; | |
| 469 | 470 |
| 470 | 471 |
| 471 struct CreateHighResTickClockTrait { | 472 struct CreateHighResTickClockTrait { |
| 472 static TickClock* Create() { | 473 static TickClock* Create() { |
| 473 // Check if the installed hardware supports a high-resolution performance | 474 // Check if the installed hardware supports a high-resolution performance |
| 474 // counter, and if not fallback to the low-resolution tick clock. | 475 // counter, and if not fallback to the low-resolution tick clock. |
| 475 LARGE_INTEGER ticks_per_second; | 476 LARGE_INTEGER ticks_per_second; |
| 476 if (!QueryPerformanceFrequency(&ticks_per_second)) { | 477 if (!QueryPerformanceFrequency(&ticks_per_second)) { |
| 477 return tick_clock.Pointer(); | 478 return tick_clock.Pointer(); |
| 478 } | 479 } |
| 479 | 480 |
| 480 // On Athlon X2 CPUs (e.g. model 15) the QueryPerformanceCounter | 481 // On Athlon X2 CPUs (e.g. model 15) the QueryPerformanceCounter |
| 481 // is unreliable, fallback to the low-resolution tick clock. | 482 // is unreliable, fallback to the low-resolution tick clock. |
| 482 CPU cpu; | 483 CPU cpu; |
| 483 if (strcmp(cpu.vendor(), "AuthenticAMD") == 0 && cpu.family() == 15) { | 484 if (strcmp(cpu.vendor(), "AuthenticAMD") == 0 && cpu.family() == 15) { |
| 484 return tick_clock.Pointer(); | 485 return tick_clock.Pointer(); |
| 485 } | 486 } |
| 486 | 487 |
| 487 return new HighResolutionTickClock(ticks_per_second.QuadPart); | 488 return new HighResolutionTickClock(ticks_per_second.QuadPart); |
| 488 } | 489 } |
| 489 }; | 490 }; |
| 490 | 491 |
| 491 | 492 |
| 492 static LazyDynamicInstance<TickClock, | 493 static base::LazyDynamicInstance<TickClock, |
| 493 CreateHighResTickClockTrait, | 494 CreateHighResTickClockTrait, |
| 494 ThreadSafeInitOnceTrait>::type high_res_tick_clock = | 495 base::ThreadSafeInitOnceTrait>::type high_res_tick_clock = |
| 495 LAZY_DYNAMIC_INSTANCE_INITIALIZER; | 496 LAZY_DYNAMIC_INSTANCE_INITIALIZER; |
| 496 | 497 |
| 497 | 498 |
| 498 TimeTicks TimeTicks::Now() { | 499 TimeTicks TimeTicks::Now() { |
| 499 // Make sure we never return 0 here. | 500 // Make sure we never return 0 here. |
| 500 TimeTicks ticks(tick_clock.Pointer()->Now()); | 501 TimeTicks ticks(tick_clock.Pointer()->Now()); |
| 501 ASSERT(!ticks.IsNull()); | 502 ASSERT(!ticks.IsNull()); |
| 502 return ticks; | 503 return ticks; |
| 503 } | 504 } |
| 504 | 505 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 559 | 560 |
| 560 | 561 |
| 561 // static | 562 // static |
| 562 bool TimeTicks::IsHighResolutionClockWorking() { | 563 bool TimeTicks::IsHighResolutionClockWorking() { |
| 563 return true; | 564 return true; |
| 564 } | 565 } |
| 565 | 566 |
| 566 #endif // V8_OS_WIN | 567 #endif // V8_OS_WIN |
| 567 | 568 |
| 568 } } // namespace v8::internal | 569 } } // namespace v8::internal |
| OLD | NEW |