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

Unified Diff: base/time/time_win.cc

Issue 446203002: Initialize the now_funciton to the HighResNowWrapper in case High Res is supported (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove the now_function static Initializer Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/time/time.h ('k') | chrome/browser/chrome_browser_main_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/time/time_win.cc
diff --git a/base/time/time_win.cc b/base/time/time_win.cc
index 492b54a93f126717ad0b2c339e75322bdeeb1532..9cd86111e78de81ae8195d797d7870d306429ae9 100644
--- a/base/time/time_win.cc
+++ b/base/time/time_win.cc
@@ -373,21 +373,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() {
@@ -422,16 +425,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;
@@ -460,7 +453,6 @@ TimeDelta HighResNowWrapper() {
}
typedef TimeDelta (*NowFunction)(void);
-NowFunction now_function = RolloverProtectedNow;
bool CPUReliablySupportsHighResTime() {
base::CPU cpu;
@@ -474,6 +466,23 @@ bool CPUReliablySupportsHighResTime() {
return true;
}
+TimeDelta InitialNowFunction();
+
+NowFunction now_function = InitialNowFunction;
+
+TimeDelta InitialNowFunction() {
+ if (!CPUReliablySupportsHighResTime()) {
+ InterlockedExchangePointer(
+ reinterpret_cast<volatile PVOID*>(&now_function),
+ reinterpret_cast<PVOID>(RolloverProtectedNow));
+ return RolloverProtectedNow();
+ }
+ InterlockedExchangePointer(
+ reinterpret_cast<volatile PVOID*>(&now_function),
+ reinterpret_cast<PVOID>(HighResNowWrapper));
+ return HighResNowWrapper();
+}
+
} // namespace
// static
@@ -488,16 +497,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();
}
« no previous file with comments | « base/time/time.h ('k') | chrome/browser/chrome_browser_main_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698