From b2edd830b1493ac7fb03a89ce6975769e2a3cbda Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 24 Aug 2012 09:47:55 +0200 Subject: [PATCH] QDnsLookupRunnable: replace a volatile bool with an atomic int Since there is non-atomic data that is protected by 'triedResolve', the (outer) read from triedResolve needs to have acquire, and the store needs to have release semantics. The release implied by the mutex unlock is not good enough because it only synchronises-with the locking of the same mutex, which not all threads execute. Change-Id: If46b3ea6ccfdd66ca41ce44d4f45bef2c2c30f72 Reviewed-by: Thiago Macieira Reviewed-by: Shane Kearns --- src/network/kernel/qdnslookup_unix.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/network/kernel/qdnslookup_unix.cpp b/src/network/kernel/qdnslookup_unix.cpp index 300f99d..1b8f66b 100644 --- a/src/network/kernel/qdnslookup_unix.cpp +++ b/src/network/kernel/qdnslookup_unix.cpp @@ -107,12 +107,12 @@ static void resolveLibrary() void QDnsLookupRunnable::query(const int requestType, const QByteArray &requestName, QDnsLookupReply *reply) { // Load dn_expand, res_ninit and res_nquery 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_ninit)); - if (!triedResolve) { + if (!triedResolve.load()) { resolveLibrary(); - triedResolve = true; + triedResolve.storeRelease(true); } } -- 2.7.4