From 48a73353029104a4d2c5fda2c9fb007d1924c9ec Mon Sep 17 00:00:00 2001 From: Konstantin Ritt <ritt.ks@gmail.com> Date: Fri, 7 Oct 2011 14:45:12 +0200 Subject: make QElapsedTimer use QSystemLibrary on win we also need to ensure the counterFrequency was already set up, thus volatile (which fixes possible race condition) Merge-request: 2655 Reviewed-by: Jan-Arve Saether <jan-arve.saether@nokia.com> --- src/corelib/tools/qelapsedtimer_win.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/corelib/tools/qelapsedtimer_win.cpp b/src/corelib/tools/qelapsedtimer_win.cpp index d79dc5d..e6bce27 100644 --- a/src/corelib/tools/qelapsedtimer_win.cpp +++ b/src/corelib/tools/qelapsedtimer_win.cpp @@ -42,6 +42,8 @@ #include "qelapsedtimer.h" #include <windows.h> +#include <private/qsystemlibrary_p.h> + typedef ULONGLONG (WINAPI *PtrGetTickCount64)(void); static PtrGetTickCount64 ptrGetTickCount64 = 0; @@ -52,21 +54,17 @@ static quint64 counterFrequency = 0; static void resolveLibs() { - static bool done = false; + static volatile bool done = false; if (done) return; // try to get GetTickCount64 from the system - HMODULE kernel32 = GetModuleHandleW(L"kernel32"); - if (!kernel32) + QSystemLibrary kernel32(QLatin1String("kernel32")); + if (!kernel32.load()) return; -#if defined(Q_OS_WINCE) // does this function exist on WinCE, or will ever exist? - ptrGetTickCount64 = (PtrGetTickCount64)GetProcAddress(kernel32, L"GetTickCount64"); -#else - ptrGetTickCount64 = (PtrGetTickCount64)GetProcAddress(kernel32, "GetTickCount64"); -#endif + ptrGetTickCount64 = (PtrGetTickCount64)kernel32.resolve("GetTickCount64"); // Retrieve the number of high-resolution performance counter ticks per second LARGE_INTEGER frequency; -- cgit v0.12