mirror of
https://github.com/tnodir/fort
synced 2024-11-15 08:35:08 +00:00
ControlManager: Fix worker's completion waiting.
This commit is contained in:
parent
33b642655b
commit
dd7a9d54c9
@ -116,7 +116,8 @@ void ControlManager::processRequest(const QString &scriptPath,
|
||||
|
||||
void ControlManager::setupWorker()
|
||||
{
|
||||
m_worker = new ControlWorker(&m_semaphore, &m_sharedMemory); // autoDelete = true
|
||||
m_worker = new ControlWorker(&m_semaphore, &m_sharedMemory, this);
|
||||
m_worker->setAutoDelete(false);
|
||||
|
||||
connect(m_worker, &ControlWorker::requestReady,
|
||||
this, &ControlManager::processRequest);
|
||||
@ -131,5 +132,6 @@ void ControlManager::abort()
|
||||
m_worker->disconnect(this);
|
||||
|
||||
m_worker->abort();
|
||||
m_worker->deleteLater();
|
||||
m_worker = nullptr;
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ ControlWorker::ControlWorker(QSystemSemaphore *semaphore,
|
||||
QObject *parent) :
|
||||
QObject(parent),
|
||||
m_aborted(false),
|
||||
m_finished(false),
|
||||
m_semaphore(semaphore),
|
||||
m_sharedMemory(sharedMemory)
|
||||
{
|
||||
@ -22,8 +21,6 @@ void ControlWorker::run()
|
||||
while (!m_aborted && m_semaphore->acquire()) {
|
||||
processRequest();
|
||||
}
|
||||
|
||||
m_finished = true;
|
||||
}
|
||||
|
||||
void ControlWorker::abort()
|
||||
@ -32,9 +29,12 @@ void ControlWorker::abort()
|
||||
|
||||
m_semaphore->release();
|
||||
|
||||
m_mutex.lock();
|
||||
if (!m_finished) {
|
||||
m_mutex.unlock();
|
||||
// Wait thread finishing
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
|
||||
m_semaphore = nullptr;
|
||||
m_sharedMemory = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,6 @@ private:
|
||||
|
||||
private:
|
||||
volatile bool m_aborted;
|
||||
volatile bool m_finished;
|
||||
|
||||
QSystemSemaphore *m_semaphore;
|
||||
QSharedMemory *m_sharedMemory;
|
||||
|
Loading…
Reference in New Issue
Block a user