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>bb10
parent
9ec05e4f36
commit
1b14569753
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -180,9 +180,6 @@ void tst_QMutexLocker::lockerStateTest()
|
|||
QMutexLocker locker(&mutex);
|
||||
QVERIFY(locker.isLocked());
|
||||
|
||||
locker.relock();
|
||||
QVERIFY(locker.isLocked());
|
||||
|
||||
locker.unlock();
|
||||
QVERIFY(!locker.isLocked());
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue