Index: base/time/time_win.cc |
diff --git a/base/time/time_win.cc b/base/time/time_win.cc |
index 5fa899d1f97f69be69d1df65ba854565d7240b53..27bcd1876da0d414ad14764c96b88d98561da722 100644 |
--- a/base/time/time_win.cc |
+++ b/base/time/time_win.cc |
@@ -359,21 +359,24 @@ bool IsBuggyAthlon(const base::CPU& cpu) { |
class HighResNowSingleton { |
public: |
HighResNowSingleton() |
- : ticks_per_second_(0), |
- skew_(0) { |
- InitializeClock(); |
+ : ticks_per_second_(0), |
+ skew_(0) { |
base::CPU cpu; |
if (IsBuggyAthlon(cpu)) |
- DisableHighResClock(); |
- } |
+ return; |
- bool IsUsingHighResClock() { |
- return ticks_per_second_ != 0.0; |
+ // Synchronize the QPC clock with GetSystemTimeAsFileTime. |
+ LARGE_INTEGER ticks_per_sec = {0}; |
+ if (!QueryPerformanceFrequency(&ticks_per_sec)) |
+ return; // QPC is not available. |
+ ticks_per_second_ = ticks_per_sec.QuadPart; |
+ |
+ skew_ = UnreliableNow() - ReliableNow(); |
} |
- void DisableHighResClock() { |
- ticks_per_second_ = 0.0; |
+ bool IsUsingHighResClock() { |
+ return ticks_per_second_ != 0; |
} |
TimeDelta Now() { |
@@ -408,16 +411,6 @@ class HighResNowSingleton { |
} |
private: |
- // Synchronize the QPC clock with GetSystemTimeAsFileTime. |
- void InitializeClock() { |
- LARGE_INTEGER ticks_per_sec = {0}; |
- if (!QueryPerformanceFrequency(&ticks_per_sec)) |
- return; // Broken, we don't guarantee this function works. |
- ticks_per_second_ = ticks_per_sec.QuadPart; |
- |
- skew_ = UnreliableNow() - ReliableNow(); |
- } |
- |
// Get the number of microseconds since boot in an unreliable fashion. |
int64 UnreliableNow() { |
LARGE_INTEGER now; |
@@ -446,7 +439,6 @@ TimeDelta HighResNowWrapper() { |
} |
typedef TimeDelta (*NowFunction)(void); |
-NowFunction now_function = RolloverProtectedNow; |
bool CPUReliablySupportsHighResTime() { |
base::CPU cpu; |
@@ -460,6 +452,14 @@ bool CPUReliablySupportsHighResTime() { |
return true; |
} |
+NowFunction GetNowFunction() { |
+ if (!CPUReliablySupportsHighResTime()) |
+ return RolloverProtectedNow; |
+ return HighResNowWrapper; |
+} |
+ |
+NowFunction now_function = GetNowFunction(); |
willchan no longer on Chromium
2014/08/25 23:07:25
FYI: this results in a static initializer. This ma
M-A Ruel
2014/08/26 02:03:19
Furthermore, the static initializer is unneeded:
|
+ |
} // namespace |
// static |
@@ -474,16 +474,6 @@ TimeTicks::TickFunctionType TimeTicks::SetMockTickFunction( |
} |
// static |
-bool TimeTicks::SetNowIsHighResNowIfSupported() { |
- if (!CPUReliablySupportsHighResTime()) { |
- return false; |
- } |
- |
- now_function = HighResNowWrapper; |
- return true; |
-} |
- |
-// static |
TimeTicks TimeTicks::Now() { |
return TimeTicks() + now_function(); |
} |