Use the 3-argument testAndSet in the fetchAndXxx operations

Saves us from an extra load in the loop when the result is already
there.

Change-Id: Ib65b5b13f27975b8fc88be9b888c19505bf5e07c
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
This commit is contained in:
Thiago Macieira 2014-07-23 17:29:54 -07:00
parent 324351f6c9
commit 63efdf9851

View File

@ -294,9 +294,9 @@ template <typename BaseClass> struct QGenericAtomicOps
T fetchAndAndRelaxed(T &_q_value, typename QtPrivate::QEnableIf<QTypeInfo<T>::isIntegral, T>::Type operand) Q_DECL_NOTHROW
{
// implement fetchAndAnd on top of testAndSet
T tmp = BaseClass::load(_q_value);
Q_FOREVER {
T tmp = BaseClass::load(_q_value);
if (BaseClass::testAndSetRelaxed(_q_value, tmp, T(tmp & operand)))
if (BaseClass::testAndSetRelaxed(_q_value, tmp, T(tmp & operand), &tmp))
return tmp;
}
}
@ -327,9 +327,9 @@ template <typename BaseClass> struct QGenericAtomicOps
T fetchAndOrRelaxed(T &_q_value, typename QtPrivate::QEnableIf<QTypeInfo<T>::isIntegral, T>::Type operand) Q_DECL_NOTHROW
{
// implement fetchAndOr on top of testAndSet
T tmp = BaseClass::load(_q_value);
Q_FOREVER {
T tmp = BaseClass::load(_q_value);
if (BaseClass::testAndSetRelaxed(_q_value, tmp, T(tmp | operand)))
if (BaseClass::testAndSetRelaxed(_q_value, tmp, T(tmp | operand), &tmp))
return tmp;
}
}
@ -360,9 +360,9 @@ template <typename BaseClass> struct QGenericAtomicOps
T fetchAndXorRelaxed(T &_q_value, typename QtPrivate::QEnableIf<QTypeInfo<T>::isIntegral, T>::Type operand) Q_DECL_NOTHROW
{
// implement fetchAndXor on top of testAndSet
T tmp = BaseClass::load(_q_value);
Q_FOREVER {
T tmp = BaseClass::load(_q_value);
if (BaseClass::testAndSetRelaxed(_q_value, tmp, T(tmp ^ operand)))
if (BaseClass::testAndSetRelaxed(_q_value, tmp, T(tmp ^ operand), &tmp))
return tmp;
}
}