diff options
-rw-r--r-- | src/network/kernel/qhostinfo_unix.cpp | 9 | ||||
-rw-r--r-- | src/network/kernel/qhostinfo_win.cpp | 9 |
2 files changed, 10 insertions, 8 deletions
diff --git a/src/network/kernel/qhostinfo_unix.cpp b/src/network/kernel/qhostinfo_unix.cpp index b696265ee4..e3f6885924 100644 --- a/src/network/kernel/qhostinfo_unix.cpp +++ b/src/network/kernel/qhostinfo_unix.cpp @@ -48,6 +48,7 @@ #include "qiodevice.h" #include <qbytearray.h> #include <qlibrary.h> +#include <qbasicatomic.h> #include <qurl.h> #include <qfile.h> #include <private/qmutexpool_p.h> @@ -127,12 +128,12 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName) #endif // Load res_init on demand. - static volatile bool triedResolve = false; - if (!triedResolve) { + static QBasicAtomicInt triedResolve = Q_BASIC_ATOMIC_INITIALIZER(false); + if (!triedResolve.loadAcquire()) { QMutexLocker locker(QMutexPool::globalInstanceGet(&local_res_init)); - if (!triedResolve) { + if (!triedResolve.load()) { resolveLibrary(); - triedResolve = true; + triedResolve.storeRelease(true); } } diff --git a/src/network/kernel/qhostinfo_win.cpp b/src/network/kernel/qhostinfo_win.cpp index 8ace68d961..5c91d75e5c 100644 --- a/src/network/kernel/qhostinfo_win.cpp +++ b/src/network/kernel/qhostinfo_win.cpp @@ -46,6 +46,7 @@ #include <ws2tcpip.h> #include <private/qsystemlibrary_p.h> #include <qmutex.h> +#include <qbasicatomic.h> #include <qurl.h> #include <private/qmutexpool_p.h> @@ -121,12 +122,12 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName) QWindowsSockInit winSock; // Load res_init on demand. - static volatile bool triedResolve = false; - if (!triedResolve) { + static QBasicAtomicInt triedResolve = Q_BASIC_ATOMIC_INITIALIZER(false); + if (!triedResolve.loadAcquire()) { QMutexLocker locker(QMutexPool::globalInstanceGet(&local_getaddrinfo)); - if (!triedResolve) { + if (!triedResolve.load()) { resolveLibrary(); - triedResolve = true; + triedResolve.storeRelease(true); } } |