From: Marc Mutz Date: Fri, 24 Aug 2012 07:47:55 +0000 (+0200) Subject: QHostInfo: replace a volatile bool with an atomic int X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=462a266edf88c763db221e547ba96fdfd2a6222b;p=profile%2Fivi%2Fqtbase.git 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 Reviewed-by: Shane Kearns --- diff --git a/src/network/kernel/qhostinfo_unix.cpp b/src/network/kernel/qhostinfo_unix.cpp index b696265..e3f6885 100644 --- a/src/network/kernel/qhostinfo_unix.cpp +++ b/src/network/kernel/qhostinfo_unix.cpp @@ -48,6 +48,7 @@ #include "qiodevice.h" #include #include +#include #include #include #include @@ -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 8ace68d..5c91d75 100644 --- a/src/network/kernel/qhostinfo_win.cpp +++ b/src/network/kernel/qhostinfo_win.cpp @@ -46,6 +46,7 @@ #include #include #include +#include #include #include @@ -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); } }