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

View File

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

View File

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