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