From 129a8ce3898091c7a6a84b9b0b68fa32b7ce61bd Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 18 Sep 2013 16:21:35 +0200 Subject: qatomic_cxx11: fix fetchAndAdd*() In qatomic_cxx11, the 'Type' is std::atomic, whose fetch_add method, used in fetchAndAdd*(), already does the right thing for T* with sizeof(T) > 1. The code, however, applied 'AddScale' to the 'valueToAdd', thus becoming incompatible with normal pointer arithmetics. This is very apparent when one goes to the length of actually testing qatomic_cxx11 with tst_QAtomicPointer (which is non-trivial, since the -c++11 configure option currently doesn't have an effect on tests/auto). To fix, remove the AddScale factor. Change-Id: I7507203af3b7df31d8322b31a6a1a33ca847d224 Reviewed-by: Thiago Macieira --- src/corelib/arch/qatomic_cxx11.h | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'src/corelib/arch') diff --git a/src/corelib/arch/qatomic_cxx11.h b/src/corelib/arch/qatomic_cxx11.h index ed19064724..55e71e1e88 100644 --- a/src/corelib/arch/qatomic_cxx11.h +++ b/src/corelib/arch/qatomic_cxx11.h @@ -219,29 +219,25 @@ template struct QAtomicOps template static inline T fetchAndAddRelaxed(std::atomic &_q_value, typename QAtomicAdditiveType::AdditiveT valueToAdd) Q_DECL_NOTHROW { - return _q_value.fetch_add(valueToAdd * QAtomicAdditiveType::AddScale, - std::memory_order_relaxed); + return _q_value.fetch_add(valueToAdd, std::memory_order_relaxed); } template static inline T fetchAndAddAcquire(std::atomic &_q_value, typename QAtomicAdditiveType::AdditiveT valueToAdd) Q_DECL_NOTHROW { - return _q_value.fetch_add(valueToAdd * QAtomicAdditiveType::AddScale, - std::memory_order_acquire); + return _q_value.fetch_add(valueToAdd, std::memory_order_acquire); } template static inline T fetchAndAddRelease(std::atomic &_q_value, typename QAtomicAdditiveType::AdditiveT valueToAdd) Q_DECL_NOTHROW { - return _q_value.fetch_add(valueToAdd * QAtomicAdditiveType::AddScale, - std::memory_order_release); + return _q_value.fetch_add(valueToAdd, std::memory_order_release); } template static inline T fetchAndAddOrdered(std::atomic &_q_value, typename QAtomicAdditiveType::AdditiveT valueToAdd) Q_DECL_NOTHROW { - return _q_value.fetch_add(valueToAdd * QAtomicAdditiveType::AddScale, - std::memory_order_acq_rel); + return _q_value.fetch_add(valueToAdd, std::memory_order_acq_rel); } }; -- cgit v1.2.3