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 <Friedemann.Kleint@qt.io>
Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Thiago Macieira 2016-06-06 09:12:21 -07:00
parent a7ae92e67d
commit 48fd845c61

View File

@ -40,35 +40,21 @@
#include "qelapsedtimer.h"
#include <qt_windows.h>
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;