diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2019-09-10 19:27:43 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2019-09-13 10:47:17 +0200 |
commit | 68b30a23a8ee66de4da62dcddfe2072c01945c24 (patch) | |
tree | bf6239988dd9841e2f9a251ec428c9b647cce053 /src/corelib/thread | |
parent | 351c738fc4586bf354c9363fb78e190bdfca4617 (diff) |
Port QReadWriteLock from QMutexLocker to qt_unique_lock
Most of these are unique_locks because they call QWaitCondition::wait()
and it doesn't feel right to use qt_scoped_lock if the lock is dropped
within the scope.
Change-Id: I506eede63008dad135c21112e578da4f7684e528
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/corelib/thread')
-rw-r--r-- | src/corelib/thread/qreadwritelock.cpp | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/corelib/thread/qreadwritelock.cpp b/src/corelib/thread/qreadwritelock.cpp index 30e9b95a52..14654986a0 100644 --- a/src/corelib/thread/qreadwritelock.cpp +++ b/src/corelib/thread/qreadwritelock.cpp @@ -48,6 +48,7 @@ #include "qreadwritelock_p.h" #include "qelapsedtimer.h" #include "private/qfreelist_p.h" +#include "private/qlocking_p.h" QT_BEGIN_NAMESPACE @@ -262,7 +263,7 @@ bool QReadWriteLock::tryLockForRead(int timeout) if (d->recursive) return d->recursiveLockForRead(timeout); - QMutexLocker lock(&d->mutex); + auto lock = qt_unique_lock(d->mutex); if (d != d_ptr.loadRelaxed()) { // d_ptr has changed: this QReadWriteLock was unlocked before we had // time to lock d->mutex. @@ -369,7 +370,7 @@ bool QReadWriteLock::tryLockForWrite(int timeout) if (d->recursive) return d->recursiveLockForWrite(timeout); - QMutexLocker lock(&d->mutex); + auto lock = qt_unique_lock(d->mutex); if (d != d_ptr.loadRelaxed()) { // The mutex was unlocked before we had time to lock the mutex. // We are holding to a mutex within a QReadWriteLockPrivate that is already released @@ -418,7 +419,7 @@ void QReadWriteLock::unlock() return; } - QMutexLocker locker(&d->mutex); + const auto lock = qt_scoped_lock(d->mutex); if (d->writerCount) { Q_ASSERT(d->writerCount == 1); Q_ASSERT(d->readerCount == 0); @@ -536,7 +537,7 @@ void QReadWriteLockPrivate::unlock() bool QReadWriteLockPrivate::recursiveLockForRead(int timeout) { Q_ASSERT(recursive); - QMutexLocker lock(&mutex); + auto lock = qt_unique_lock(mutex); Qt::HANDLE self = QThread::currentThreadId(); @@ -556,7 +557,7 @@ bool QReadWriteLockPrivate::recursiveLockForRead(int timeout) bool QReadWriteLockPrivate::recursiveLockForWrite(int timeout) { Q_ASSERT(recursive); - QMutexLocker lock(&mutex); + auto lock = qt_unique_lock(mutex); Qt::HANDLE self = QThread::currentThreadId(); if (currentWriter == self) { @@ -574,7 +575,7 @@ bool QReadWriteLockPrivate::recursiveLockForWrite(int timeout) void QReadWriteLockPrivate::recursiveUnlock() { Q_ASSERT(recursive); - QMutexLocker lock(&mutex); + auto lock = qt_unique_lock(mutex); Qt::HANDLE self = QThread::currentThreadId(); if (self == currentWriter) { |