From 1e8479b2aa781e6ce3fadf01294023fbc6ddbc22 Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Fri, 7 Oct 2011 14:45:47 +0200 Subject: don't lock the global mutex if there is nothing to protect according to Thiago, setting the pointer with the same values *is* thread-safe Merge-request: 2655 Reviewed-by: Jan-Arve Saether --- src/corelib/kernel/qeventdispatcher_win.cpp | 6 ------ src/gui/dialogs/qfiledialog_win.cpp | 17 ----------------- src/network/kernel/qhostinfo_win.cpp | 20 ++++++++------------ src/plugins/bearer/nativewifi/main.cpp | 14 +------------- 4 files changed, 9 insertions(+), 48 deletions(-) diff --git a/src/corelib/kernel/qeventdispatcher_win.cpp b/src/corelib/kernel/qeventdispatcher_win.cpp index 365b28e..c135c4a 100644 --- a/src/corelib/kernel/qeventdispatcher_win.cpp +++ b/src/corelib/kernel/qeventdispatcher_win.cpp @@ -53,7 +53,6 @@ #include "qabstracteventdispatcher_p.h" #include "qcoreapplication_p.h" #include -#include QT_BEGIN_NAMESPACE @@ -322,11 +321,6 @@ static void resolveTimerAPI() { static bool triedResolve = false; if (!triedResolve) { -#ifndef QT_NO_THREAD - QMutexLocker locker(QMutexPool::globalInstanceGet(&triedResolve)); - if (triedResolve) - return; -#endif #ifndef Q_OS_WINCE QSystemLibrary library(QLatin1String("Mmtimer")); #else diff --git a/src/gui/dialogs/qfiledialog_win.cpp b/src/gui/dialogs/qfiledialog_win.cpp index 45f6164..32dbe4f 100644 --- a/src/gui/dialogs/qfiledialog_win.cpp +++ b/src/gui/dialogs/qfiledialog_win.cpp @@ -55,10 +55,6 @@ #include #include "qfiledialog_win_p.h" -#ifndef QT_NO_THREAD -# include -#endif - #ifdef Q_WS_WINCE #include bool qt_priv_ptr_valid = false; @@ -83,20 +79,7 @@ QT_BEGIN_NAMESPACE static void qt_win_resolve_libs() { static bool triedResolve = false; - if (!triedResolve) { -#ifndef QT_NO_THREAD - // protect initialization - QMutexLocker locker(QMutexPool::globalInstanceGet(&triedResolve)); - // check triedResolve again, since another thread may have already - // done the initialization - if (triedResolve) { - // another thread did initialize the security function pointers, - // so we shouldn't do it again. - return; - } -#endif - #if !defined(Q_WS_WINCE) QSystemLibrary lib(QLatin1String("shell32")); ptrSHBrowseForFolder = (PtrSHBrowseForFolder)lib.resolve("SHBrowseForFolderW"); diff --git a/src/network/kernel/qhostinfo_win.cpp b/src/network/kernel/qhostinfo_win.cpp index 03e72c4..1cbf350 100644 --- a/src/network/kernel/qhostinfo_win.cpp +++ b/src/network/kernel/qhostinfo_win.cpp @@ -45,9 +45,7 @@ #include "private/qnativesocketengine_p.h" #include #include -#include #include -#include QT_BEGIN_NAMESPACE @@ -84,6 +82,10 @@ static void resolveLibrary() { // Attempt to resolve getaddrinfo(); without it we'll have to fall // back to gethostbyname(), which has no IPv6 support. + static bool triedResolve = false; + if (triedResolve) + return; + #if !defined(Q_OS_WINCE) QSystemLibrary ws2lib(QLatin1String("ws2_32")); #else @@ -94,6 +96,8 @@ static void resolveLibrary() local_freeaddrinfo = (freeaddrinfoProto)ws2lib.resolve("freeaddrinfo"); local_getnameinfo = (getnameinfoProto)ws2lib.resolve("getnameinfo"); } + + triedResolve = true; } #if defined(Q_OS_WINCE) @@ -103,21 +107,13 @@ QMutex qPrivCEMutex; QHostInfo QHostInfoAgent::fromName(const QString &hostName) { + resolveLibrary(); + #if defined(Q_OS_WINCE) QMutexLocker locker(&qPrivCEMutex); #endif QWindowsSockInit winSock; - // Load res_init on demand. - static volatile bool triedResolve = false; - if (!triedResolve) { - QMutexLocker locker(QMutexPool::globalInstanceGet(&local_getaddrinfo)); - if (!triedResolve) { - resolveLibrary(); - triedResolve = true; - } - } - QHostInfo results; #if defined(QHOSTINFO_DEBUG) diff --git a/src/plugins/bearer/nativewifi/main.cpp b/src/plugins/bearer/nativewifi/main.cpp index cbdfd99..d279631 100644 --- a/src/plugins/bearer/nativewifi/main.cpp +++ b/src/plugins/bearer/nativewifi/main.cpp @@ -42,30 +42,18 @@ #include "qnativewifiengine.h" #include "platformdefs.h" -#include -#include #include #include -#include - #ifndef QT_NO_BEARERMANAGEMENT QT_BEGIN_NAMESPACE static void resolveLibrary() { - static volatile bool triedResolve = false; - + static bool triedResolve = false; if (!triedResolve) { -#ifndef QT_NO_THREAD - QMutexLocker locker(QMutexPool::globalInstanceGet(&local_WlanOpenHandle)); -#endif - - if (triedResolve) - return; - QSystemLibrary wlanapi(QLatin1String("wlanapi")); if (wlanapi.load()) { local_WlanOpenHandle = (WlanOpenHandleProto) -- cgit v0.12