mirror of
https://github.com/tnodir/fort
synced 2024-11-15 11:25:08 +00:00
UI: WorkerManager: Fix workers waiting on exit
This commit is contained in:
parent
c5c2b834b9
commit
2928fdb57b
@ -36,8 +36,8 @@ void WorkerManager::workerFinished(WorkerObject *worker)
|
|||||||
|
|
||||||
m_workers.removeOne(worker);
|
m_workers.removeOne(worker);
|
||||||
|
|
||||||
if (m_workers.isEmpty()) {
|
if (m_workers.isEmpty() && aborted()) {
|
||||||
m_waitCondition.wakeOne();
|
m_abortWaitCondition.wakeOne();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,10 +59,10 @@ void WorkerManager::abortWorkers()
|
|||||||
|
|
||||||
m_aborted = true;
|
m_aborted = true;
|
||||||
|
|
||||||
m_waitCondition.wakeAll();
|
m_jobWaitCondition.wakeAll();
|
||||||
|
|
||||||
while (!m_workers.isEmpty()) {
|
while (!m_workers.isEmpty()) {
|
||||||
m_waitCondition.wait(&m_mutex);
|
m_abortWaitCondition.wait(&m_mutex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,19 +77,19 @@ void WorkerManager::enqueueJob(WorkerJobPtr job)
|
|||||||
|
|
||||||
m_jobQueue.enqueue(job);
|
m_jobQueue.enqueue(job);
|
||||||
|
|
||||||
m_waitCondition.wakeOne();
|
m_jobWaitCondition.wakeOne();
|
||||||
}
|
}
|
||||||
|
|
||||||
WorkerJobPtr WorkerManager::dequeueJob()
|
WorkerJobPtr WorkerManager::dequeueJob()
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&m_mutex);
|
QMutexLocker locker(&m_mutex);
|
||||||
|
|
||||||
while (!m_aborted && m_jobQueue.isEmpty()) {
|
while (!aborted() && m_jobQueue.isEmpty()) {
|
||||||
if (!m_waitCondition.wait(&m_mutex, WORKER_TIMEOUT_MSEC))
|
if (!m_jobWaitCondition.wait(&m_mutex, WORKER_TIMEOUT_MSEC))
|
||||||
break; // timed out
|
break; // timed out
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_aborted || m_jobQueue.isEmpty())
|
if (aborted() || m_jobQueue.isEmpty())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
return m_jobQueue.dequeue();
|
return m_jobQueue.dequeue();
|
||||||
|
@ -52,7 +52,8 @@ private:
|
|||||||
QQueue<WorkerJobPtr> m_jobQueue;
|
QQueue<WorkerJobPtr> m_jobQueue;
|
||||||
|
|
||||||
QMutex m_mutex;
|
QMutex m_mutex;
|
||||||
QWaitCondition m_waitCondition;
|
QWaitCondition m_jobWaitCondition;
|
||||||
|
QWaitCondition m_abortWaitCondition;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // WORKERMANAGER_H
|
#endif // WORKERMANAGER_H
|
||||||
|
Loading…
Reference in New Issue
Block a user