summaryrefslogtreecommitdiffstats
path: root/src/network/kernel/qhostinfo_unix.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2016-04-28 18:36:31 -0700
committerThiago Macieira <thiago.macieira@intel.com>2016-04-30 03:01:10 +0000
commitc9f9f54d3f79915723270b2a6d06216a54c87433 (patch)
treeaed56cca07c1e35426f3c1f25d453429d9144937 /src/network/kernel/qhostinfo_unix.cpp
parentfda6324b4d471c2163c94d0c451a4bb4671b7b18 (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/network/kernel/qhostinfo_unix.cpp')
-rw-r--r--src/network/kernel/qhostinfo_unix.cpp17
1 files changed, 6 insertions, 11 deletions
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)