mirror of
https://github.com/moonlight-stream/moonlight-qt
synced 2024-12-17 06:33:07 +00:00
Ensure delayed flushes complete during shutdown
This commit is contained in:
parent
5bfe56472f
commit
a13f8e7937
1 changed files with 11 additions and 6 deletions
|
@ -188,6 +188,9 @@ ComputerManager::~ComputerManager()
|
||||||
// Wait for it to terminate (and finish any pending flush)
|
// Wait for it to terminate (and finish any pending flush)
|
||||||
m_DelayedFlushThread->wait();
|
m_DelayedFlushThread->wait();
|
||||||
delete m_DelayedFlushThread;
|
delete m_DelayedFlushThread;
|
||||||
|
|
||||||
|
// Delayed flushes should have completed by now
|
||||||
|
Q_ASSERT(!m_NeedsDelayedFlush);
|
||||||
}
|
}
|
||||||
|
|
||||||
QWriteLocker lock(&m_Lock);
|
QWriteLocker lock(&m_Lock);
|
||||||
|
@ -220,7 +223,7 @@ ComputerManager::~ComputerManager()
|
||||||
}
|
}
|
||||||
|
|
||||||
void DelayedFlushThread::run() {
|
void DelayedFlushThread::run() {
|
||||||
while (!QThread::currentThread()->isInterruptionRequested()) {
|
for (;;) {
|
||||||
// Wait for a delayed flush request or an interruption
|
// Wait for a delayed flush request or an interruption
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&m_ComputerManager->m_DelayedFlushMutex);
|
QMutexLocker locker(&m_ComputerManager->m_DelayedFlushMutex);
|
||||||
|
@ -229,15 +232,17 @@ void DelayedFlushThread::run() {
|
||||||
m_ComputerManager->m_DelayedFlushCondition.wait(&m_ComputerManager->m_DelayedFlushMutex);
|
m_ComputerManager->m_DelayedFlushCondition.wait(&m_ComputerManager->m_DelayedFlushMutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Bail without flushing if we woke up for an interruption alone.
|
||||||
|
// If we have both an interruption and a flush request, do the flush.
|
||||||
|
if (!m_ComputerManager->m_NeedsDelayedFlush) {
|
||||||
|
Q_ASSERT(QThread::currentThread()->isInterruptionRequested());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// Reset the delayed flush flag to ensure any racing saveHosts() call will set it again
|
// Reset the delayed flush flag to ensure any racing saveHosts() call will set it again
|
||||||
m_ComputerManager->m_NeedsDelayedFlush = false;
|
m_ComputerManager->m_NeedsDelayedFlush = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (QThread::currentThread()->isInterruptionRequested()) {
|
|
||||||
// Bail without flushing if we woke up for an interruption
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Perform the flush
|
// Perform the flush
|
||||||
{
|
{
|
||||||
QReadLocker lock(&m_ComputerManager->m_Lock);
|
QReadLocker lock(&m_ComputerManager->m_Lock);
|
||||||
|
|
Loading…
Reference in a new issue