Index: base/time_win.cc |
diff --git a/base/time_win.cc b/base/time_win.cc |
index 71c914da29dabe75003d9e83172269d3ac72a717..1efd287a092a0cb7ce0df5a1b1bad37bda5852f5 100644 |
--- a/base/time_win.cc |
+++ b/base/time_win.cc |
@@ -344,11 +344,11 @@ class HighResNowSingleton { |
} |
bool IsUsingHighResClock() { |
- return ticks_per_microsecond_ != 0.0; |
+ return ticks_per_second_ != 0.0; |
} |
void DisableHighResClock() { |
- ticks_per_microsecond_ = 0.0; |
+ ticks_per_second_ = 0.0; |
} |
TimeDelta Now() { |
@@ -371,9 +371,15 @@ class HighResNowSingleton { |
return abs(static_cast<long>((UnreliableNow() - ReliableNow()) - skew_)); |
} |
+ int64 QPCValueToMicroseconds(LONGLONG qpc_value) { |
+ if (ticks_per_second_) |
+ return qpc_value * Time::kMicrosecondsPerSecond / ticks_per_second_; |
jar (doing other things)
2012/08/02 03:13:20
nit: 2 character indent from start of "if"
|
+ return 0; |
+ } |
+ |
private: |
HighResNowSingleton() |
- : ticks_per_microsecond_(0.0), |
+ : ticks_per_second_(0), |
jbates
2012/08/02 03:10:34
what's the reason for changing to per_second? seem
brianderson
2012/08/02 19:04:14
Using ticks per second, we are dividing by the act
|
skew_(0) { |
InitializeClock(); |
@@ -389,8 +395,7 @@ class HighResNowSingleton { |
LARGE_INTEGER ticks_per_sec = {0}; |
if (!QueryPerformanceFrequency(&ticks_per_sec)) |
return; // Broken, we don't guarantee this function works. |
- ticks_per_microsecond_ = static_cast<float>(ticks_per_sec.QuadPart) / |
- static_cast<float>(Time::kMicrosecondsPerSecond); |
+ ticks_per_second_ = ticks_per_sec.QuadPart; |
skew_ = UnreliableNow() - ReliableNow(); |
} |
@@ -399,7 +404,7 @@ class HighResNowSingleton { |
int64 UnreliableNow() { |
LARGE_INTEGER now; |
QueryPerformanceCounter(&now); |
- return static_cast<int64>(now.QuadPart / ticks_per_microsecond_); |
+ return now.QuadPart * Time::kMicrosecondsPerSecond / ticks_per_second_; |
jar (doing other things)
2012/08/02 03:13:20
I think this is going to work ok (working with int
|
} |
// Get the number of microseconds since boot in a reliable fashion. |
@@ -409,7 +414,7 @@ class HighResNowSingleton { |
// Cached clock frequency -> microseconds. This assumes that the clock |
jar (doing other things)
2012/08/02 03:13:20
Comment should be changed or removed.
|
// frequency is faster than one microsecond (which is 1MHz, should be OK). |
- float ticks_per_microsecond_; // 0 indicates QPF failed and we're broken. |
+ int64 ticks_per_second_; // 0 indicates QPF failed and we're broken. |
int64 skew_; // Skew between lo-res and hi-res clocks (for debugging). |
friend struct DefaultSingletonTraits<HighResNowSingleton>; |
@@ -446,6 +451,20 @@ int64 TimeTicks::GetQPCDriftMicroseconds() { |
} |
// static |
+TimeTicks TimeTicks::FromQPCValue(LONGLONG qpc_value) { |
+ return TimeTicks( |
+ HighResNowSingleton::GetInstance()->QPCValueToMicroseconds(qpc_value)); |
+} |
+ |
+// static |
bool TimeTicks::IsHighResClockWorking() { |
return HighResNowSingleton::GetInstance()->IsUsingHighResClock(); |
} |
+ |
+// TimeDelta ------------------------------------------------------------------ |
+ |
+// static |
+TimeDelta TimeDelta::FromQPCValue(LONGLONG qpc_value) { |
+ return TimeDelta( |
+ HighResNowSingleton::GetInstance()->QPCValueToMicroseconds(qpc_value)); |
+} |