From a14048f0a23b0e50576ab3b5e87aebd616b35d43 Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Mon, 19 Feb 2018 12:50:59 +0100 Subject: Use GetTickCount64 without a GetProcAddress check in Timestamp_windows.cpp. Tag #22. --- mozglue/misc/TimeStamp_windows.cpp | 56 ++++---------------------------------- 1 file changed, 6 insertions(+), 50 deletions(-) (limited to 'mozglue/misc') 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( - 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)); } -- cgit v1.2.3