nsresult TimeStamp::Startup() { // Decide which implementation to use for the high-performance timer. InitializeCriticalSectionAndSpinCount(&sTimeStampLock, kLockSpinCount); LARGE_INTEGER freq; BOOL QPCAvailable = ::QueryPerformanceFrequency(&freq); if (!QPCAvailable) { // No Performance Counter. Fall back to use GetTickCount. sFrequencyPerSec = 1; sFallBackToGTC = true; InitResolution(); LOG(("TimeStamp: using GetTickCount")); return NS_OK; } sFrequencyPerSec = freq.QuadPart; ULONGLONG qpc = PerformanceCounter(); sLastCalibrated = TickCount64(::GetTickCount()); sSkew = qpc - ms2mt(sLastCalibrated); InitThresholds(); InitResolution(); LOG(("TimeStamp: initial skew is %1.2fms", mt2ms_d(sSkew))); return NS_OK; }
MFBT_API void TimeStamp::Startup() { if (gInitialized) { return; } 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(); LOG(("TimeStamp: HasStableTSC=%d", sHasStableTSC)); LARGE_INTEGER freq; sUseQPC = ::QueryPerformanceFrequency(&freq); if (!sUseQPC) { // No Performance Counter. Fall back to use GetTickCount. InitResolution(); LOG(("TimeStamp: using GetTickCount")); return; } sFrequencyPerSec = freq.QuadPart; LOG(("TimeStamp: QPC frequency=%llu", sFrequencyPerSec)); InitThresholds(); InitResolution(); return; }