QMutexLocker: add isLocked()
It's basically for free. [ChangeLog][QtCore][QMutexLocker] Added the isLocked() function. Change-Id: Idad5fa249ba8f135dcf81c7b7596caa3a888e99c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
07b176ce70
commit
9b8015ed8d
@ -494,6 +494,14 @@ void QRecursiveMutex::unlock() noexcept
|
||||
\sa QMutex::unlock()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename Mutex> bool QMutexLocker<Mutex>::isLocked() const noexcept
|
||||
\since 6.4
|
||||
|
||||
Returns true if this QMutexLocker is currently locking its associated
|
||||
mutex, or false otherwise.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename Mutex> void QMutexLocker<Mutex>::unlock() noexcept
|
||||
|
||||
|
@ -252,6 +252,11 @@ public:
|
||||
unlock();
|
||||
}
|
||||
|
||||
inline bool isLocked() const noexcept
|
||||
{
|
||||
return m_isLocked;
|
||||
}
|
||||
|
||||
inline void unlock() noexcept
|
||||
{
|
||||
if (!m_isLocked)
|
||||
|
@ -80,6 +80,7 @@ void tst_QMutexLocker::scopeTest()
|
||||
|
||||
{
|
||||
QMutexLocker locker(&mutex);
|
||||
QVERIFY(locker.isLocked());
|
||||
waitForTest();
|
||||
}
|
||||
|
||||
@ -122,16 +123,23 @@ void tst_QMutexLocker::unlockAndRelockTest()
|
||||
void run() override
|
||||
{
|
||||
QMutexLocker locker(&mutex);
|
||||
QVERIFY(locker.isLocked());
|
||||
|
||||
waitForTest();
|
||||
|
||||
QVERIFY(locker.isLocked());
|
||||
locker.unlock();
|
||||
QVERIFY(!locker.isLocked());
|
||||
|
||||
waitForTest();
|
||||
|
||||
QVERIFY(!locker.isLocked());
|
||||
locker.relock();
|
||||
QVERIFY(locker.isLocked());
|
||||
|
||||
waitForTest();
|
||||
|
||||
QVERIFY(locker.isLocked());
|
||||
}
|
||||
};
|
||||
|
||||
@ -169,10 +177,16 @@ void tst_QMutexLocker::lockerStateTest()
|
||||
{
|
||||
{
|
||||
QMutexLocker locker(&mutex);
|
||||
QVERIFY(locker.isLocked());
|
||||
|
||||
locker.relock();
|
||||
QVERIFY(locker.isLocked());
|
||||
|
||||
locker.unlock();
|
||||
QVERIFY(!locker.isLocked());
|
||||
|
||||
waitForTest();
|
||||
QVERIFY(!locker.isLocked());
|
||||
}
|
||||
|
||||
waitForTest();
|
||||
|
Loading…
Reference in New Issue
Block a user