Use the new 3-operand testAndSet functions in QMutex
This allows us to get the current value of the QMutex / QBasicMutex after the testAndSet operation failed. It saves an extra load from memory. Change-Id: I4922a8b3df15e342b177b13f56cf4f1184314520 Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
This commit is contained in:
parent
0ebfd0866d
commit
d84da39964
@ -216,9 +216,9 @@ QMutex::~QMutex()
|
|||||||
*/
|
*/
|
||||||
void QMutex::lock() QT_MUTEX_LOCK_NOEXCEPT
|
void QMutex::lock() QT_MUTEX_LOCK_NOEXCEPT
|
||||||
{
|
{
|
||||||
if (fastTryLock())
|
QMutexData *current;
|
||||||
|
if (fastTryLock(current))
|
||||||
return;
|
return;
|
||||||
QMutexData *current = d_ptr.loadAcquire();
|
|
||||||
if (QT_PREPEND_NAMESPACE(isRecursive)(current))
|
if (QT_PREPEND_NAMESPACE(isRecursive)(current))
|
||||||
static_cast<QRecursiveMutexPrivate *>(current)->lock(-1);
|
static_cast<QRecursiveMutexPrivate *>(current)->lock(-1);
|
||||||
else
|
else
|
||||||
@ -250,9 +250,9 @@ void QMutex::lock() QT_MUTEX_LOCK_NOEXCEPT
|
|||||||
*/
|
*/
|
||||||
bool QMutex::tryLock(int timeout) QT_MUTEX_LOCK_NOEXCEPT
|
bool QMutex::tryLock(int timeout) QT_MUTEX_LOCK_NOEXCEPT
|
||||||
{
|
{
|
||||||
if (fastTryLock())
|
QMutexData *current;
|
||||||
|
if (fastTryLock(current))
|
||||||
return true;
|
return true;
|
||||||
QMutexData *current = d_ptr.loadAcquire();
|
|
||||||
if (QT_PREPEND_NAMESPACE(isRecursive)(current))
|
if (QT_PREPEND_NAMESPACE(isRecursive)(current))
|
||||||
return static_cast<QRecursiveMutexPrivate *>(current)->lock(timeout);
|
return static_cast<QRecursiveMutexPrivate *>(current)->lock(timeout);
|
||||||
else
|
else
|
||||||
@ -268,9 +268,9 @@ bool QMutex::tryLock(int timeout) QT_MUTEX_LOCK_NOEXCEPT
|
|||||||
*/
|
*/
|
||||||
void QMutex::unlock() Q_DECL_NOTHROW
|
void QMutex::unlock() Q_DECL_NOTHROW
|
||||||
{
|
{
|
||||||
if (fastTryUnlock())
|
QMutexData *current;
|
||||||
|
if (fastTryUnlock(current))
|
||||||
return;
|
return;
|
||||||
QMutexData *current = d_ptr.loadAcquire();
|
|
||||||
if (QT_PREPEND_NAMESPACE(isRecursive)(current))
|
if (QT_PREPEND_NAMESPACE(isRecursive)(current))
|
||||||
static_cast<QRecursiveMutexPrivate *>(current)->unlock();
|
static_cast<QRecursiveMutexPrivate *>(current)->unlock();
|
||||||
else
|
else
|
||||||
|
@ -86,6 +86,12 @@ private:
|
|||||||
inline bool fastTryUnlock() Q_DECL_NOTHROW {
|
inline bool fastTryUnlock() Q_DECL_NOTHROW {
|
||||||
return d_ptr.testAndSetRelease(dummyLocked(), 0);
|
return d_ptr.testAndSetRelease(dummyLocked(), 0);
|
||||||
}
|
}
|
||||||
|
inline bool fastTryLock(QMutexData *¤t) Q_DECL_NOTHROW {
|
||||||
|
return d_ptr.testAndSetAcquire(0, dummyLocked(), current);
|
||||||
|
}
|
||||||
|
inline bool fastTryUnlock(QMutexData *¤t) Q_DECL_NOTHROW {
|
||||||
|
return d_ptr.testAndSetRelease(dummyLocked(), 0, current);
|
||||||
|
}
|
||||||
|
|
||||||
void lockInternal() QT_MUTEX_LOCK_NOEXCEPT;
|
void lockInternal() QT_MUTEX_LOCK_NOEXCEPT;
|
||||||
bool lockInternal(int timeout) QT_MUTEX_LOCK_NOEXCEPT;
|
bool lockInternal(int timeout) QT_MUTEX_LOCK_NOEXCEPT;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user