summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2012-08-24 09:47:55 +0200
committerQt by Nokia <qt-info@nokia.com>2012-08-29 14:14:17 +0200
commit462a266edf88c763db221e547ba96fdfd2a6222b (patch)
tree61825b51f46f3a4fc2b74f60713c68733b4c256c
parente0d38745258e12a2615030674ff022641dabffef (diff)
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>
-rw-r--r--src/network/kernel/qhostinfo_unix.cpp9
-rw-r--r--src/network/kernel/qhostinfo_win.cpp9
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);
}
}