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

Unified Diff: base/time/time_win.cc

Issue 516693002: Revert of 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: Created 6 years, 4 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 27bcd1876da0d414ad14764c96b88d98561da722..5fa899d1f97f69be69d1df65ba854565d7240b53 100644
--- a/base/time/time_win.cc
+++ b/base/time/time_win.cc
@@ -359,24 +359,21 @@
class HighResNowSingleton {
public:
HighResNowSingleton()
- : ticks_per_second_(0),
- skew_(0) {
+ : ticks_per_second_(0),
+ skew_(0) {
+ InitializeClock();
base::CPU cpu;
if (IsBuggyAthlon(cpu))
- return;
-
- // 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();
+ DisableHighResClock();
}
bool IsUsingHighResClock() {
- return ticks_per_second_ != 0;
+ return ticks_per_second_ != 0.0;
+ }
+
+ void DisableHighResClock() {
+ ticks_per_second_ = 0.0;
}
TimeDelta Now() {
@@ -411,6 +408,16 @@
}
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;
@@ -439,6 +446,7 @@
}
typedef TimeDelta (*NowFunction)(void);
+NowFunction now_function = RolloverProtectedNow;
bool CPUReliablySupportsHighResTime() {
base::CPU cpu;
@@ -451,14 +459,6 @@
return true;
}
-
-NowFunction GetNowFunction() {
- if (!CPUReliablySupportsHighResTime())
- return RolloverProtectedNow;
- return HighResNowWrapper;
-}
-
-NowFunction now_function = GetNowFunction();
} // namespace
@@ -474,6 +474,16 @@
}
// 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