diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2016-04-28 18:36:31 -0700 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2016-04-30 03:01:10 +0000 |
commit | c9f9f54d3f79915723270b2a6d06216a54c87433 (patch) | |
tree | aed56cca07c1e35426f3c1f25d453429d9144937 /src | |
parent | fda6324b4d471c2163c94d0c451a4bb4671b7b18 (diff) |
Remove the use of QMutexPool in QHostInfo and QDnsLookup
Q_GLOBAL_STATIC does the thread-safe protection for us. And who said we
could only use non-POD types? We can just use a boolean!
Change-Id: Ifea6e497f11a461db432ffff1449b0a88d75d194
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/network/kernel/qdnslookup_unix.cpp | 17 | ||||
-rw-r--r-- | src/network/kernel/qhostinfo_unix.cpp | 17 | ||||
-rw-r--r-- | src/network/kernel/qhostinfo_win.cpp | 14 |
3 files changed, 16 insertions, 32 deletions
diff --git a/src/network/kernel/qdnslookup_unix.cpp b/src/network/kernel/qdnslookup_unix.cpp index dc8ec5a300..cb3bdfe8ff 100644 --- a/src/network/kernel/qdnslookup_unix.cpp +++ b/src/network/kernel/qdnslookup_unix.cpp @@ -36,7 +36,6 @@ #include <qlibrary.h> #include <qscopedpointer.h> #include <qurl.h> -#include <private/qmutexpool_p.h> #include <sys/types.h> #include <netinet/in.h> @@ -71,7 +70,7 @@ struct QDnsLookupStateDeleter } }; -static void resolveLibrary() +static bool resolveLibraryInternal() { QLibrary lib; #ifdef LIBRESOLV_SO @@ -81,7 +80,7 @@ static void resolveLibrary() { lib.setFileName(QLatin1String("resolv")); if (!lib.load()) - return; + return false; } local_dn_expand = dn_expand_proto(lib.resolve("__dn_expand")); @@ -105,19 +104,15 @@ static void resolveLibrary() local_res_nquery = res_nquery_proto(lib.resolve("res_9_nquery")); if (!local_res_nquery) local_res_nquery = res_nquery_proto(lib.resolve("res_nquery")); + + return true; } +Q_GLOBAL_STATIC_WITH_ARGS(bool, resolveLibrary, (resolveLibraryInternal())) void QDnsLookupRunnable::query(const int requestType, const QByteArray &requestName, const QHostAddress &nameserver, QDnsLookupReply *reply) { // Load dn_expand, res_ninit and res_nquery on demand. - static QBasicAtomicInt triedResolve = Q_BASIC_ATOMIC_INITIALIZER(false); - if (!triedResolve.loadAcquire()) { - QMutexLocker locker(QMutexPool::globalInstanceGet(&local_res_ninit)); - if (!triedResolve.load()) { - resolveLibrary(); - triedResolve.storeRelease(true); - } - } + resolveLibrary(); // If dn_expand, res_ninit or res_nquery is missing, fail. if (!local_dn_expand || !local_res_nclose || !local_res_ninit || !local_res_nquery) { diff --git a/src/network/kernel/qhostinfo_unix.cpp b/src/network/kernel/qhostinfo_unix.cpp index 266a67771c..dabf1913cc 100644 --- a/src/network/kernel/qhostinfo_unix.cpp +++ b/src/network/kernel/qhostinfo_unix.cpp @@ -43,7 +43,6 @@ #include <qbasicatomic.h> #include <qurl.h> #include <qfile.h> -#include <private/qmutexpool_p.h> #include <private/qnet_unix_p.h> #include <sys/types.h> @@ -86,7 +85,7 @@ typedef void (*res_nclose_proto)(res_state_ptr); static res_nclose_proto local_res_nclose = 0; static res_state_ptr local_res = 0; -static void resolveLibrary() +static bool resolveLibraryInternal() { #if !defined(QT_NO_LIBRARY) && !defined(Q_OS_QNX) QLibrary lib; @@ -97,7 +96,7 @@ static void resolveLibrary() { lib.setFileName(QLatin1String("resolv")); if (!lib.load()) - return; + return false; } local_res_init = res_init_proto(lib.resolve("__res_init")); @@ -119,7 +118,10 @@ static void resolveLibrary() local_res_ninit = 0; } #endif + + return true; } +Q_GLOBAL_STATIC_WITH_ARGS(bool, resolveLibrary, (resolveLibraryInternal())) QHostInfo QHostInfoAgent::fromName(const QString &hostName) { @@ -131,14 +133,7 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName) #endif // Load res_init on demand. - static QBasicAtomicInt triedResolve = Q_BASIC_ATOMIC_INITIALIZER(false); - if (!triedResolve.loadAcquire()) { - QMutexLocker locker(QMutexPool::globalInstanceGet(&local_res_init)); - if (!triedResolve.load()) { - resolveLibrary(); - triedResolve.storeRelease(true); - } - } + resolveLibrary(); // If res_init is available, poll it. if (local_res_init) diff --git a/src/network/kernel/qhostinfo_win.cpp b/src/network/kernel/qhostinfo_win.cpp index 7e45e9f949..58816b355d 100644 --- a/src/network/kernel/qhostinfo_win.cpp +++ b/src/network/kernel/qhostinfo_win.cpp @@ -39,7 +39,6 @@ #include <qmutex.h> #include <qbasicatomic.h> #include <qurl.h> -#include <private/qmutexpool_p.h> QT_BEGIN_NAMESPACE @@ -72,7 +71,7 @@ static getnameinfoProto local_getnameinfo = 0; static getaddrinfoProto local_getaddrinfo = 0; static freeaddrinfoProto local_freeaddrinfo = 0; -static void resolveLibrary() +static bool resolveLibraryInternal() { // Attempt to resolve getaddrinfo(); without it we'll have to fall // back to gethostbyname(), which has no IPv6 support. @@ -89,7 +88,9 @@ static void resolveLibrary() local_freeaddrinfo = (freeaddrinfoProto) QSystemLibrary::resolve(QLatin1String("ws2_32"), "freeaddrinfo"); local_getnameinfo = (getnameinfoProto) QSystemLibrary::resolve(QLatin1String("ws2_32"), "getnameinfo"); #endif + return true; } +Q_GLOBAL_STATIC_WITH_ARGS(bool, resolveLibrary, (resolveLibraryInternal())) static void translateWSAError(int error, QHostInfo *results) { @@ -117,14 +118,7 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName) QSysInfo::machineHostName(); // this initializes ws2_32.dll // Load res_init on demand. - static QBasicAtomicInt triedResolve = Q_BASIC_ATOMIC_INITIALIZER(false); - if (!triedResolve.loadAcquire()) { - QMutexLocker locker(QMutexPool::globalInstanceGet(&local_getaddrinfo)); - if (!triedResolve.load()) { - resolveLibrary(); - triedResolve.storeRelease(true); - } - } + resolveLibrary(); QHostInfo results; |