diff options
author | wolfbeast <mcwerewolf@gmail.com> | 2018-02-19 12:50:59 +0100 |
---|---|---|
committer | wolfbeast <mcwerewolf@gmail.com> | 2018-02-19 12:50:59 +0100 |
commit | a14048f0a23b0e50576ab3b5e87aebd616b35d43 (patch) | |
tree | ee9a974becf9528cd9b64865f4bd656908894a0a /mozglue/misc/TimeStamp_windows.cpp | |
parent | 39578317eebdc75fb25f6b434772a11e724c1ebd (diff) | |
download | UXP-a14048f0a23b0e50576ab3b5e87aebd616b35d43.tar UXP-a14048f0a23b0e50576ab3b5e87aebd616b35d43.tar.gz UXP-a14048f0a23b0e50576ab3b5e87aebd616b35d43.tar.lz UXP-a14048f0a23b0e50576ab3b5e87aebd616b35d43.tar.xz UXP-a14048f0a23b0e50576ab3b5e87aebd616b35d43.zip |
Use GetTickCount64 without a GetProcAddress check in Timestamp_windows.cpp.
Tag #22.
Diffstat (limited to 'mozglue/misc/TimeStamp_windows.cpp')
-rw-r--r-- | mozglue/misc/TimeStamp_windows.cpp | 56 |
1 files changed, 6 insertions, 50 deletions
diff --git a/mozglue/misc/TimeStamp_windows.cpp b/mozglue/misc/TimeStamp_windows.cpp index cd519affd..683c2209a 100644 --- a/mozglue/misc/TimeStamp_windows.cpp +++ b/mozglue/misc/TimeStamp_windows.cpp @@ -5,7 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ // Implement TimeStamp::Now() with QueryPerformanceCounter() controlled with -// values of GetTickCount(). +// values of GetTickCount64(). #include "mozilla/MathAlgorithms.h" #include "mozilla/TimeStamp.h" @@ -69,7 +69,7 @@ static const DWORD kDefaultTimeIncrement = 156001; * further just referred as [mt], meaning milli-ticks. * * This is needed to preserve maximum precision of the performance frequency - * representation. GetTickCount values in milliseconds are multiplied with + * representation. GetTickCount64 values in milliseconds are multiplied with * frequency per second. Therefor we need to multiply QPC value by 1000 to * have the same units to allow simple arithmentic with both QPC and GTC. */ @@ -156,41 +156,8 @@ static CRITICAL_SECTION sTimeStampLock; // Kept in [mt] static ULONGLONG sFaultIntoleranceCheckpoint = 0; -// Used only when GetTickCount64 is not available on the platform. -// Last result of GetTickCount call. -// -// Kept in [ms] -static DWORD sLastGTCResult = 0; - -// Higher part of the 64-bit value of MozGetTickCount64, -// incremented atomically. -static DWORD sLastGTCRollover = 0; - namespace mozilla { -typedef ULONGLONG (WINAPI* GetTickCount64_t)(); -static GetTickCount64_t sGetTickCount64 = nullptr; - -// Function protecting GetTickCount result from rolling over, -// result is in [ms] -static ULONGLONG WINAPI -MozGetTickCount64() -{ - DWORD GTC = ::GetTickCount(); - - // Cheaper then CMPXCHG8B - AutoCriticalSection lock(&sTimeStampLock); - - // Pull the rollover counter forward only if new value of GTC goes way - // down under the last saved result - if ((sLastGTCResult > GTC) && ((sLastGTCResult - GTC) > (1UL << 30))) { - ++sLastGTCRollover; - } - - sLastGTCResult = GTC; - return ULONGLONG(sLastGTCRollover) << 32 | sLastGTCResult; -} - // Result is in [mt] static inline ULONGLONG PerformanceCounter() @@ -355,7 +322,7 @@ TimeStampValue::CheckQPC(const TimeStampValue& aOther) const if (duration < sHardFailureLimit) { // Interval between the two time stamps is very short, consider // QPC as unstable and record a failure. - uint64_t now = ms2mt(sGetTickCount64()); + uint64_t now = ms2mt(GetTickCount64()); AutoCriticalSection lock(&sTimeStampLock); @@ -485,17 +452,6 @@ TimeStamp::Startup() gInitialized = true; - // Decide which implementation to use for the high-performance timer. - - HMODULE kernelDLL = GetModuleHandleW(L"kernel32.dll"); - sGetTickCount64 = reinterpret_cast<GetTickCount64_t>( - GetProcAddress(kernelDLL, "GetTickCount64")); - if (!sGetTickCount64) { - // If the platform does not support the GetTickCount64 (Windows XP doesn't), - // then use our fallback implementation based on GetTickCount. - sGetTickCount64 = MozGetTickCount64; - } - InitializeCriticalSectionAndSpinCount(&sTimeStampLock, kLockSpinCount); sHasStableTSC = HasStableTSC(); @@ -504,10 +460,10 @@ TimeStamp::Startup() LARGE_INTEGER freq; sUseQPC = ::QueryPerformanceFrequency(&freq); if (!sUseQPC) { - // No Performance Counter. Fall back to use GetTickCount. + // No Performance Counter. Fall back to use GetTickCount64. InitResolution(); - LOG(("TimeStamp: using GetTickCount")); + LOG(("TimeStamp: using GetTickCount64")); return; } @@ -534,7 +490,7 @@ TimeStamp::Now(bool aHighResolution) // Both values are in [mt] units. ULONGLONG QPC = useQPC ? PerformanceCounter() : uint64_t(0); - ULONGLONG GTC = ms2mt(sGetTickCount64()); + ULONGLONG GTC = ms2mt(GetTickCount64()); return TimeStamp(TimeStampValue(GTC, QPC, useQPC)); } |