Optimise QMutexLocker a little: don't call relock() in the constructor

QMutexLocker does not support being passed already-locked mutexes,
unless they are recursive mutexes. But in that case, it behaves as if
the mutex weren't locked in the first place.

Since that's the case, there's no point in testing the low bit to see if
it's set or not. It's never going to be.

Change-Id: Ie4b81f7e2cca16e6db36f3cb51a5377dbdfc157d
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
This commit is contained in:
Thiago Macieira 2012-08-01 17:54:32 +02:00 committed by Qt by Nokia
parent 96bc8835eb
commit 38dc1f7597

View File

@ -116,8 +116,11 @@ public:
Q_ASSERT_X((reinterpret_cast<quintptr>(m) & quintptr(1u)) == quintptr(0),
"QMutexLocker", "QMutex pointer is misaligned");
val = quintptr(m);
// relock() here ensures that we call QMutex::lock() instead of QBasicMutex::lock()
relock();
if (Q_LIKELY(m)) {
// call QMutex::lock() instead of QBasicMutex::lock()
static_cast<QMutex *>(m)->lock();
val |= 1;
}
}
inline ~QMutexLocker() { unlock(); }