UI: WorkerManager: Wait workers finishing.

This commit is contained in:
Nodir Temirkhodjaev 2019-04-13 21:52:53 +05:00
parent baffe6aba5
commit b89e685212
3 changed files with 14 additions and 14 deletions

View File

@ -40,6 +40,10 @@ void WorkerManager::workerFinished(WorkerObject *worker)
QMutexLocker locker(&m_mutex); QMutexLocker locker(&m_mutex);
m_workers.removeOne(worker); m_workers.removeOne(worker);
if (m_workers.isEmpty()) {
m_waitCondition.wakeOne();
}
} }
void WorkerManager::clear() void WorkerManager::clear()
@ -53,20 +57,19 @@ void WorkerManager::abort()
{ {
QMutexLocker locker(&m_mutex); QMutexLocker locker(&m_mutex);
abortWorkers();
m_aborted = true; m_aborted = true;
m_waitCondition.wakeAll(); if (!m_workers.isEmpty()) {
}
void WorkerManager::abortWorkers()
{
for (WorkerObject *worker : m_workers) { for (WorkerObject *worker : m_workers) {
worker->abort(); worker->abort();
} }
m_workers.clear(); m_waitCondition.wakeAll();
do {
m_waitCondition.wait(&m_mutex);
} while (!m_workers.isEmpty());
}
} }
void WorkerManager::enqueueJob(const QString &job) void WorkerManager::enqueueJob(const QString &job)

View File

@ -41,7 +41,6 @@ private:
void setupWorker(); void setupWorker();
void abort(); void abort();
void abortWorkers();
private: private:
volatile bool m_aborted; volatile bool m_aborted;

View File

@ -19,7 +19,5 @@ void WorkerObject::run()
doJob(job); doJob(job);
} }
if (!aborted()) {
manager()->workerFinished(this); manager()->workerFinished(this);
}
} }