QHostInfo: replace a volatile bool with an atomic int
A volatile bool read/store is documented on MSVC to have acquire/release semantics, respectively, but that doesn't need to be true for MinGW, so use explicit memory ordering. Apply the same fix to the Unix implementation, too. Change-Id: Ica466cec50beed830aafa4e3384d82f02e1a47e8 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Shane Kearns <shane.kearns@accenture.com>
This commit is contained in:
parent
e0d3874525
commit
462a266edf
@ -48,6 +48,7 @@
|
|||||||
#include "qiodevice.h"
|
#include "qiodevice.h"
|
||||||
#include <qbytearray.h>
|
#include <qbytearray.h>
|
||||||
#include <qlibrary.h>
|
#include <qlibrary.h>
|
||||||
|
#include <qbasicatomic.h>
|
||||||
#include <qurl.h>
|
#include <qurl.h>
|
||||||
#include <qfile.h>
|
#include <qfile.h>
|
||||||
#include <private/qmutexpool_p.h>
|
#include <private/qmutexpool_p.h>
|
||||||
@ -127,12 +128,12 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Load res_init on demand.
|
// Load res_init on demand.
|
||||||
static volatile bool triedResolve = false;
|
static QBasicAtomicInt triedResolve = Q_BASIC_ATOMIC_INITIALIZER(false);
|
||||||
if (!triedResolve) {
|
if (!triedResolve.loadAcquire()) {
|
||||||
QMutexLocker locker(QMutexPool::globalInstanceGet(&local_res_init));
|
QMutexLocker locker(QMutexPool::globalInstanceGet(&local_res_init));
|
||||||
if (!triedResolve) {
|
if (!triedResolve.load()) {
|
||||||
resolveLibrary();
|
resolveLibrary();
|
||||||
triedResolve = true;
|
triedResolve.storeRelease(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,6 +46,7 @@
|
|||||||
#include <ws2tcpip.h>
|
#include <ws2tcpip.h>
|
||||||
#include <private/qsystemlibrary_p.h>
|
#include <private/qsystemlibrary_p.h>
|
||||||
#include <qmutex.h>
|
#include <qmutex.h>
|
||||||
|
#include <qbasicatomic.h>
|
||||||
#include <qurl.h>
|
#include <qurl.h>
|
||||||
#include <private/qmutexpool_p.h>
|
#include <private/qmutexpool_p.h>
|
||||||
|
|
||||||
@ -121,12 +122,12 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName)
|
|||||||
QWindowsSockInit winSock;
|
QWindowsSockInit winSock;
|
||||||
|
|
||||||
// Load res_init on demand.
|
// Load res_init on demand.
|
||||||
static volatile bool triedResolve = false;
|
static QBasicAtomicInt triedResolve = Q_BASIC_ATOMIC_INITIALIZER(false);
|
||||||
if (!triedResolve) {
|
if (!triedResolve.loadAcquire()) {
|
||||||
QMutexLocker locker(QMutexPool::globalInstanceGet(&local_getaddrinfo));
|
QMutexLocker locker(QMutexPool::globalInstanceGet(&local_getaddrinfo));
|
||||||
if (!triedResolve) {
|
if (!triedResolve.load()) {
|
||||||
resolveLibrary();
|
resolveLibrary();
|
||||||
triedResolve = true;
|
triedResolve.storeRelease(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user