summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/thread/qmutex.h15
-rw-r--r--tests/auto/corelib/thread/qmutexlocker/tst_qmutexlocker.cpp3
2 files changed, 6 insertions, 12 deletions
diff --git a/src/corelib/thread/qmutex.h b/src/corelib/thread/qmutex.h
index e10a3f8f3d..9423585f64 100644
--- a/src/corelib/thread/qmutex.h
+++ b/src/corelib/thread/qmutex.h
@@ -256,7 +256,8 @@ public:
inline ~QMutexLocker()
{
- unlock();
+ if (m_isLocked)
+ unlock();
}
inline bool isLocked() const noexcept
@@ -266,20 +267,16 @@ public:
inline void unlock() noexcept
{
- if (!m_isLocked)
- return;
+ Q_ASSERT(m_isLocked);
m_mutex->unlock();
m_isLocked = false;
}
inline void relock() QT_MUTEX_LOCK_NOEXCEPT
{
- if (m_isLocked)
- return;
- if (m_mutex) {
- m_mutex->lock();
- m_isLocked = true;
- }
+ Q_ASSERT(!m_isLocked);
+ m_mutex->lock();
+ m_isLocked = true;
}
inline void swap(QMutexLocker &other) noexcept
diff --git a/tests/auto/corelib/thread/qmutexlocker/tst_qmutexlocker.cpp b/tests/auto/corelib/thread/qmutexlocker/tst_qmutexlocker.cpp
index 8844dd5624..e9544d8a40 100644
--- a/tests/auto/corelib/thread/qmutexlocker/tst_qmutexlocker.cpp
+++ b/tests/auto/corelib/thread/qmutexlocker/tst_qmutexlocker.cpp
@@ -180,9 +180,6 @@ void tst_QMutexLocker::lockerStateTest()
QMutexLocker locker(&mutex);
QVERIFY(locker.isLocked());
- locker.relock();
- QVERIFY(locker.isLocked());
-
locker.unlock();
QVERIFY(!locker.isLocked());