From 48fd845c6141d8ff353f65f87d669ef1c0f22bb2 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 6 Jun 2016 09:12:21 -0700 Subject: [PATCH] QElapsedTimer: Remove legacy code dealing with Windows pre-Vista and CE GetTickCount64 is available on Windows Vista and WinRT. Since Windows CE is no longer supported on dev, we don't need to dynamically resolve the function anymore. What's more, QueryCounterFrequency is documented to never fail since Windows XP, so we haven't needed GetTickCount64 for years (no clue when we dropped support for Win2k). Change-Id: I115db302eb114bed8cd1fffd14558a81353d2aed Reviewed-by: Friedemann Kleint Reviewed-by: Maurice Kalinowski Reviewed-by: Thiago Macieira --- src/corelib/tools/qelapsedtimer_win.cpp | 49 +++++-------------------- 1 file changed, 10 insertions(+), 39 deletions(-) diff --git a/src/corelib/tools/qelapsedtimer_win.cpp b/src/corelib/tools/qelapsedtimer_win.cpp index 532d61d504..520126d262 100644 --- a/src/corelib/tools/qelapsedtimer_win.cpp +++ b/src/corelib/tools/qelapsedtimer_win.cpp @@ -40,35 +40,21 @@ #include "qelapsedtimer.h" #include -typedef ULONGLONG (WINAPI *PtrGetTickCount64)(void); -#if defined(Q_OS_WINRT) - static const PtrGetTickCount64 ptrGetTickCount64 = &GetTickCount64; -#else - static PtrGetTickCount64 ptrGetTickCount64 = 0; -#endif - QT_BEGIN_NAMESPACE // Result of QueryPerformanceFrequency, 0 indicates that the high resolution timer is unavailable static quint64 counterFrequency = 0; -static void resolveLibs() +static void resolveCounterFrequency() { static bool done = false; if (done) return; -#if !defined(Q_OS_WINRT) - // try to get GetTickCount64 from the system - HMODULE kernel32 = GetModuleHandleW(L"kernel32"); - if (!kernel32) - return; - ptrGetTickCount64 = (PtrGetTickCount64)GetProcAddress(kernel32, "GetTickCount64"); -#endif // !Q_OS_WINRT - // Retrieve the number of high-resolution performance counter ticks per second LARGE_INTEGER frequency; if (!QueryPerformanceFrequency(&frequency)) { + qFatal("QueryPerformanceFrequency failed, even though Microsoft documentation promises it wouldn't."); counterFrequency = 0; } else { counterFrequency = frequency.QuadPart; @@ -92,35 +78,20 @@ static inline qint64 ticksToNanoseconds(qint64 ticks) static quint64 getTickCount() { - resolveLibs(); + resolveCounterFrequency(); // This avoids a division by zero and disables the high performance counter if it's not available if (counterFrequency > 0) { LARGE_INTEGER counter; - if (QueryPerformanceCounter(&counter)) { - return counter.QuadPart; - } else { - qWarning("QueryPerformanceCounter failed, although QueryPerformanceFrequency succeeded."); - return 0; - } + bool ok = QueryPerformanceCounter(&counter); + Q_ASSERT_X(ok, "QElapsedTimer::start()", + "QueryPerformanceCounter failed, although QueryPerformanceFrequency succeeded."); + Q_UNUSED(ok); + return counter.QuadPart; } -#ifndef Q_OS_WINRT - if (ptrGetTickCount64) - return ptrGetTickCount64(); - - static quint32 highdword = 0; - static quint32 lastval = 0; - quint32 val = GetTickCount(); - if (val < lastval) - ++highdword; - lastval = val; - return val | (quint64(highdword) << 32); -#else // !Q_OS_WINRT - // ptrGetTickCount64 is always set on WinRT but GetTickCount is not available - return ptrGetTickCount64(); -#endif // Q_OS_WINRT + return GetTickCount64(); } quint64 qt_msectime() @@ -130,7 +101,7 @@ quint64 qt_msectime() QElapsedTimer::ClockType QElapsedTimer::clockType() Q_DECL_NOTHROW { - resolveLibs(); + resolveCounterFrequency(); if (counterFrequency > 0) return PerformanceCounter;