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>
This commit is contained in:
parent
fda6324b4d
commit
c9f9f54d3f
@ -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) {
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user