Chromium Code Reviews| Index: base/time/time_win.cc |
| diff --git a/base/time/time_win.cc b/base/time/time_win.cc |
| index dc968ad63980edbbe0280519a654447c121a74ae..c52df9c458238cf1bdb596cc827a4690f2953663 100644 |
| --- a/base/time/time_win.cc |
| +++ b/base/time/time_win.cc |
| @@ -403,6 +403,8 @@ TimeDelta InitialNowFunction(); |
| // See "threading notes" in InitializeNowFunctionPointer() for details on how |
| // concurrent reads/writes to these globals has been made safe. |
| NowFunction g_now_function = &InitialNowFunction; |
| +TimeTicks::Clock g_now_clock = TimeTicks::WIN_ROLLOVER_PROTECTED_TIME_GET_TIME; |
| + |
| int64_t g_qpc_ticks_per_second = 0; |
| // As of January 2015, use of <atomic> is forbidden in Chromium code. This is |
| @@ -459,12 +461,15 @@ void InitializeNowFunctionPointer() { |
| // Otherwise, Now uses the high-resolution QPC clock. As of 21 August 2015, |
| // ~72% of users fall within this category. |
| NowFunction now_function; |
| + const char* now_clock; |
| base::CPU cpu; |
| if (ticks_per_sec.QuadPart <= 0 || |
| !cpu.has_non_stop_time_stamp_counter() || IsBuggyAthlon(cpu)) { |
| now_function = &RolloverProtectedNow; |
| + now_clock = Clock::WIN_ROLLOVER_PROTECTED_TIME_GET_TIME; |
| } else { |
| now_function = &QPCNow; |
| + now_clock = Clock::WIN_QPC; |
| } |
| // Threading note 1: In an unlikely race condition, it's possible for two or |
| @@ -476,6 +481,7 @@ void InitializeNowFunctionPointer() { |
| // perspective of other threads using the function pointers, that the |
| // assignment to |g_qpc_ticks_per_second| happens before the function pointers |
| // are changed. |
| + g_now_clock = now_clock; |
| g_qpc_ticks_per_second = ticks_per_sec.QuadPart; |
| ATOMIC_THREAD_FENCE(memory_order_release); |
| g_now_function = now_function; |
| @@ -512,6 +518,13 @@ bool TimeTicks::IsHighResolution() { |
| } |
| // static |
| +TimeTicks::Clock TimeTicks::GetClock() { |
|
fmeawad
2016/03/30 20:25:19
nit: I might be confused, but why not something li
danakj
2016/03/30 20:26:29
Oh, that's pretty nice yah.
charliea (OOO until 10-5)
2016/03/31 15:38:38
Agreed. That's a much nicer way of doing this. Don
|
| + if (g_now_function == &InitialNowFunction) |
| + InitializeNowFunctionPointer(); |
| + return g_now_clock; |
| +} |
| + |
| +// static |
| ThreadTicks ThreadTicks::Now() { |
| DCHECK(IsSupported()); |