Atomics: implement fetchAndSub on top of fetchAndAdd
Instead of looping unnecessarily on top of testAndSet. Task-number: QTBUG-37031 Change-Id: I8120f8405eb76dccc9066749cee0a92b0f2da20e Reviewed-by: Olivier Goffart <ogoffart@woboq.com> Reviewed-by: Sergio Ahumada <sahumada@blackberry.com>
This commit is contained in:
parent
380de7f8e7
commit
e7f685002b
@ -264,12 +264,8 @@ template <typename BaseClass> struct QGenericAtomicOps
|
||||
template <typename T> static inline always_inline
|
||||
T fetchAndSubRelaxed(T &_q_value, typename QAtomicAdditiveType<T>::AdditiveT operand) Q_DECL_NOTHROW
|
||||
{
|
||||
// implement fetchAndSub on top of testAndSet
|
||||
Q_FOREVER {
|
||||
T tmp = BaseClass::load(_q_value);
|
||||
if (BaseClass::testAndSetRelaxed(_q_value, tmp, T(tmp - operand)))
|
||||
return tmp;
|
||||
}
|
||||
// implement fetchAndSub on top of fetchAndAdd
|
||||
return fetchAndAddRelaxed(_q_value, -operand);
|
||||
}
|
||||
|
||||
template <typename T> static inline always_inline
|
||||
|
Loading…
Reference in New Issue
Block a user