From 63efdf9851915ce3b81bffe089fcd1995d6750f8 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 23 Jul 2014 17:29:54 -0700 Subject: [PATCH] Use the 3-argument testAndSet in the fetchAndXxx operations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Saves us from an extra load in the loop when the result is already there. Change-Id: Ib65b5b13f27975b8fc88be9b888c19505bf5e07c Reviewed-by: Jędrzej Nowacki Reviewed-by: Olivier Goffart --- src/corelib/thread/qgenericatomic.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/corelib/thread/qgenericatomic.h b/src/corelib/thread/qgenericatomic.h index aeed199c97..3546becd77 100644 --- a/src/corelib/thread/qgenericatomic.h +++ b/src/corelib/thread/qgenericatomic.h @@ -294,9 +294,9 @@ template struct QGenericAtomicOps T fetchAndAndRelaxed(T &_q_value, typename QtPrivate::QEnableIf::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 struct QGenericAtomicOps T fetchAndOrRelaxed(T &_q_value, typename QtPrivate::QEnableIf::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 struct QGenericAtomicOps T fetchAndXorRelaxed(T &_q_value, typename QtPrivate::QEnableIf::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; } }