qatomic_cxx11: fix fetchAndAdd*()
In qatomic_cxx11, the 'Type' is std::atomic<T>, 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 <thiago.macieira@intel.com>
This commit is contained in:
parent
9efa71ac0a
commit
129a8ce389
@ -219,29 +219,25 @@ template <typename X> struct QAtomicOps
|
||||
template <typename T> static inline
|
||||
T fetchAndAddRelaxed(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
|
||||
{
|
||||
return _q_value.fetch_add(valueToAdd * QAtomicAdditiveType<T>::AddScale,
|
||||
std::memory_order_relaxed);
|
||||
return _q_value.fetch_add(valueToAdd, std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
template <typename T> static inline
|
||||
T fetchAndAddAcquire(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
|
||||
{
|
||||
return _q_value.fetch_add(valueToAdd * QAtomicAdditiveType<T>::AddScale,
|
||||
std::memory_order_acquire);
|
||||
return _q_value.fetch_add(valueToAdd, std::memory_order_acquire);
|
||||
}
|
||||
|
||||
template <typename T> static inline
|
||||
T fetchAndAddRelease(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
|
||||
{
|
||||
return _q_value.fetch_add(valueToAdd * QAtomicAdditiveType<T>::AddScale,
|
||||
std::memory_order_release);
|
||||
return _q_value.fetch_add(valueToAdd, std::memory_order_release);
|
||||
}
|
||||
|
||||
template <typename T> static inline
|
||||
T fetchAndAddOrdered(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
|
||||
{
|
||||
return _q_value.fetch_add(valueToAdd * QAtomicAdditiveType<T>::AddScale,
|
||||
std::memory_order_acq_rel);
|
||||
return _q_value.fetch_add(valueToAdd, std::memory_order_acq_rel);
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user