From 3acaa648f0ffd03c4695d0be7ed25e73724e4417 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sat, 11 Aug 2012 13:51:26 +0200 Subject: Hoist the recursive mutex check out of the inner loop A non-recursive mutex doesn't suddenly become recursive, so we don't need to check it multiple times. Change-Id: Id040254b6142d320a7bd3111491082ad09968404 Reviewed-by: Olivier Goffart --- src/corelib/thread/qmutex.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/corelib/thread/qmutex.cpp') diff --git a/src/corelib/thread/qmutex.cpp b/src/corelib/thread/qmutex.cpp index 1a064a1775..fa4fddca56 100644 --- a/src/corelib/thread/qmutex.cpp +++ b/src/corelib/thread/qmutex.cpp @@ -152,7 +152,7 @@ QMutex::QMutex(RecursionMode mode) QMutex::~QMutex() { QMutexData *d = d_ptr.load(); - if (quintptr(d) > 0x3 && d->recursive) { + if (isRecursive()) { delete static_cast(d); } else if (d) { #ifndef QT_LINUX_FUTEX @@ -234,7 +234,12 @@ bool QBasicMutex::isRecursive() { QMutexData *d = d_ptr.load(); if (quintptr(d) <= 0x3) return false; +#ifdef QT_LINUX_FUTEX + Q_ASSERT(d->recursive); + return true; +#else return d->recursive; +#endif } @@ -333,6 +338,9 @@ bool QBasicMutex::isRecursive() { */ bool QBasicMutex::lockInternal(int timeout) QT_MUTEX_LOCK_NOEXCEPT { + if (isRecursive()) + return static_cast(d_ptr.load())->lock(timeout); + while (!fastTryLock()) { QMutexData *copy = d_ptr.loadAcquire(); if (!copy) // if d is 0, the mutex is unlocked @@ -349,8 +357,6 @@ bool QBasicMutex::lockInternal(int timeout) QT_MUTEX_LOCK_NOEXCEPT } copy = newD; //the d->refCount is already 1 the deref will occurs when we unlock - } else if (copy->recursive) { - return static_cast(copy)->lock(timeout); } QMutexPrivate *d = static_cast(copy); -- cgit v1.2.3