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

Side by Side Diff: src/platform/time.cc

Issue 316133002: Move atomic ops and related files to base library (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: updates Created 6 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/platform/semaphore.h ('k') | src/runtime-profiler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #if V8_OS_WIN
17 #include "src/base/lazy-instance.h"
18 #include "src/base/win32-headers.h"
19 #endif
16 #include "src/checks.h" 20 #include "src/checks.h"
17 #include "src/cpu.h" 21 #include "src/cpu.h"
18 #include "src/platform.h" 22 #include "src/platform.h"
19 #if V8_OS_WIN
20 #include "src/win32-headers.h"
21 #endif
22 23
23 namespace v8 { 24 namespace v8 {
24 namespace internal { 25 namespace internal {
25 26
26 TimeDelta TimeDelta::FromDays(int days) { 27 TimeDelta TimeDelta::FromDays(int days) {
27 return TimeDelta(days * Time::kMicrosecondsPerDay); 28 return TimeDelta(days * Time::kMicrosecondsPerDay);
28 } 29 }
29 30
30 31
31 TimeDelta TimeDelta::FromHours(int hours) { 32 TimeDelta TimeDelta::FromHours(int hours) {
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 ::GetSystemTimeAsFileTime(&ft); 187 ::GetSystemTimeAsFileTime(&ft);
187 return Time::FromFiletime(ft); 188 return Time::FromFiletime(ft);
188 } 189 }
189 190
190 TimeTicks initial_ticks_; 191 TimeTicks initial_ticks_;
191 Time initial_time_; 192 Time initial_time_;
192 Mutex mutex_; 193 Mutex mutex_;
193 }; 194 };
194 195
195 196
196 static LazyStaticInstance<Clock, 197 static base::LazyStaticInstance<Clock, base::DefaultConstructTrait<Clock>,
197 DefaultConstructTrait<Clock>, 198 base::ThreadSafeInitOnceTrait>::type clock =
198 ThreadSafeInitOnceTrait>::type clock = LAZY_STATIC_INSTANCE_INITIALIZER; 199 LAZY_STATIC_INSTANCE_INITIALIZER;
199 200
200 201
201 Time Time::Now() { 202 Time Time::Now() {
202 return clock.Pointer()->Now(); 203 return clock.Pointer()->Now();
203 } 204 }
204 205
205 206
206 Time Time::NowFromSystemTime() { 207 Time Time::NowFromSystemTime() {
207 return clock.Pointer()->NowFromSystemTime(); 208 return clock.Pointer()->NowFromSystemTime();
208 } 209 }
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 return false; 456 return false;
456 } 457 }
457 458
458 private: 459 private:
459 Mutex mutex_; 460 Mutex mutex_;
460 DWORD last_seen_now_; 461 DWORD last_seen_now_;
461 int64_t rollover_ms_; 462 int64_t rollover_ms_;
462 }; 463 };
463 464
464 465
465 static LazyStaticInstance<RolloverProtectedTickClock, 466 static base::LazyStaticInstance<
466 DefaultConstructTrait<RolloverProtectedTickClock>, 467 RolloverProtectedTickClock,
467 ThreadSafeInitOnceTrait>::type tick_clock = 468 base::DefaultConstructTrait<RolloverProtectedTickClock>,
468 LAZY_STATIC_INSTANCE_INITIALIZER; 469 base::ThreadSafeInitOnceTrait>::type tick_clock =
470 LAZY_STATIC_INSTANCE_INITIALIZER;
469 471
470 472
471 struct CreateHighResTickClockTrait { 473 struct CreateHighResTickClockTrait {
472 static TickClock* Create() { 474 static TickClock* Create() {
473 // Check if the installed hardware supports a high-resolution performance 475 // Check if the installed hardware supports a high-resolution performance
474 // counter, and if not fallback to the low-resolution tick clock. 476 // counter, and if not fallback to the low-resolution tick clock.
475 LARGE_INTEGER ticks_per_second; 477 LARGE_INTEGER ticks_per_second;
476 if (!QueryPerformanceFrequency(&ticks_per_second)) { 478 if (!QueryPerformanceFrequency(&ticks_per_second)) {
477 return tick_clock.Pointer(); 479 return tick_clock.Pointer();
478 } 480 }
479 481
480 // On Athlon X2 CPUs (e.g. model 15) the QueryPerformanceCounter 482 // On Athlon X2 CPUs (e.g. model 15) the QueryPerformanceCounter
481 // is unreliable, fallback to the low-resolution tick clock. 483 // is unreliable, fallback to the low-resolution tick clock.
482 CPU cpu; 484 CPU cpu;
483 if (strcmp(cpu.vendor(), "AuthenticAMD") == 0 && cpu.family() == 15) { 485 if (strcmp(cpu.vendor(), "AuthenticAMD") == 0 && cpu.family() == 15) {
484 return tick_clock.Pointer(); 486 return tick_clock.Pointer();
485 } 487 }
486 488
487 return new HighResolutionTickClock(ticks_per_second.QuadPart); 489 return new HighResolutionTickClock(ticks_per_second.QuadPart);
488 } 490 }
489 }; 491 };
490 492
491 493
492 static LazyDynamicInstance<TickClock, 494 static base::LazyDynamicInstance<TickClock,
493 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;
496 498
497 499
498 TimeTicks TimeTicks::Now() { 500 TimeTicks TimeTicks::Now() {
499 // Make sure we never return 0 here. 501 // Make sure we never return 0 here.
500 TimeTicks ticks(tick_clock.Pointer()->Now()); 502 TimeTicks ticks(tick_clock.Pointer()->Now());
501 ASSERT(!ticks.IsNull()); 503 ASSERT(!ticks.IsNull());
502 return ticks; 504 return ticks;
503 } 505 }
504 506
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 561
560 562
561 // static 563 // static
562 bool TimeTicks::IsHighResolutionClockWorking() { 564 bool TimeTicks::IsHighResolutionClockWorking() {
563 return true; 565 return true;
564 } 566 }
565 567
566 #endif // V8_OS_WIN 568 #endif // V8_OS_WIN
567 569
568 } } // namespace v8::internal 570 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform/semaphore.h ('k') | src/runtime-profiler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698