summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2022-03-06 15:12:51 +0100
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2022-03-18 05:18:28 +0100
commit1b1456975347b044c11169458b53c9f6083dbc59 (patch)
tree023f05e1ff0470f9c6075e3d3a4b18f8cfc6c740 /src
parent9ec05e4f361f11796177ff2d26eaa078d733ad82 (diff)
QMutexLocker: strenghten the locking operations
There is no reason to allow relock() on a locked locker, or unlock() or an unlocked one, just like we don't allow that on a plain mutex to begin with. The docs already said that e.g. relock() locks an _unlocked_ locker. [ChangeLog][QtCore][QMutexLocker] QMutexLocker allowed relock() and unlock() on an already closed (resp. open) locker object. These semantics have always been undocumented and are now unsupported (in both cases they yield undefined behavior.) Change-Id: Id5f67beb5dc30d6435dae88a3085fba93ec7d96e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/thread/qmutex.h15
1 files changed, 6 insertions, 9 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