From ac5452a085588a8deda1f817b0d2602d6c841f05 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Sat, 18 May 2019 04:53:22 +0000 Subject: [PATCH] make QAtomicInt reference counting logic match that of QBasicAtomicInt Signed-off-by: Ivailo Monev --- src/core/thread/qatomic.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/core/thread/qatomic.h b/src/core/thread/qatomic.h index b07ce0745..a5303a01f 100644 --- a/src/core/thread/qatomic.h +++ b/src/core/thread/qatomic.h @@ -85,17 +85,15 @@ class Q_CORE_EXPORT QAtomicInt } bool ref() { - int newValue = ++m_data; - return newValue != 0; + return fetchAndAddOrdered(1) != -1; } bool deref() { - int newValue = --m_data; - return newValue != 0; + return fetchAndAddOrdered(-1) != 1; } bool testAndSetRelaxed(int expectedValue, int newValue) { - return m_data.compare_exchange_strong(expectedValue, newValue, std::memory_order_relaxed); + return m_data.compare_exchange_strong(expectedValue, newValue, std::memory_order_relaxed); } bool testAndSetAcquire(int expectedValue, int newValue) { -- 2.11.0