ControlWorker: Wait abort completion.

This commit is contained in:
Nodir Temirkhodjaev 2019-08-25 17:29:00 +05:00
parent 218407e248
commit 648a1e07cd
2 changed files with 8 additions and 1 deletions

View File

@ -16,7 +16,9 @@ ControlWorker::ControlWorker(QSystemSemaphore *semaphore,
void ControlWorker::run() void ControlWorker::run()
{ {
while (m_semaphore->acquire() && !m_aborted) { QMutexLocker locker(&m_mutex);
while (!m_aborted && m_semaphore->acquire()) {
processRequest(); processRequest();
} }
} }
@ -26,6 +28,8 @@ void ControlWorker::abort()
m_aborted = true; m_aborted = true;
m_semaphore->release(); m_semaphore->release();
m_mutex.lock();
} }
bool ControlWorker::post(const QString &scriptPath, bool ControlWorker::post(const QString &scriptPath,

View File

@ -1,6 +1,7 @@
#ifndef CONTROLWORKER_H #ifndef CONTROLWORKER_H
#define CONTROLWORKER_H #define CONTROLWORKER_H
#include <QMutex>
#include <QObject> #include <QObject>
#include <QRunnable> #include <QRunnable>
@ -44,6 +45,8 @@ private:
QSystemSemaphore *m_semaphore; QSystemSemaphore *m_semaphore;
QSharedMemory *m_sharedMemory; QSharedMemory *m_sharedMemory;
QMutex m_mutex;
}; };
#endif // CONTROLWORKER_H #endif // CONTROLWORKER_H