#3929 System : Always lock mutex before unlocking

This commit is contained in:
Magne Sjaastad 2019-01-04 08:15:26 +01:00
parent f09fa727fa
commit f727a6c4ee

View File

@ -1580,9 +1580,13 @@ std::vector<QString> RiaApplication::readFileListFromTextFile(QString listFileNa
void RiaApplication::waitUntilCommandObjectsHasBeenProcessed() void RiaApplication::waitUntilCommandObjectsHasBeenProcessed()
{ {
// Wait until all command objects have completed // Wait until all command objects have completed
while (!m_commandQueueLock.tryLock()) bool mutexLockedSuccessfully = m_commandQueueLock.tryLock();
while (!mutexLockedSuccessfully)
{ {
processEvents(); processEvents();
mutexLockedSuccessfully = m_commandQueueLock.tryLock();
} }
m_commandQueueLock.unlock(); m_commandQueueLock.unlock();
} }
@ -2219,6 +2223,8 @@ void RiaApplication::executeCommandObjects()
else else
{ {
// Unlock the command queue lock when the command queue is empty // Unlock the command queue lock when the command queue is empty
// Required to lock the mutex before unlocking to avoid undefined behavior
m_commandQueueLock.tryLock();
m_commandQueueLock.unlock(); m_commandQueueLock.unlock();
} }
} }