From 0e236f8acc87b14d16c6ce403a269efd0b385981 Mon Sep 17 00:00:00 2001 From: f4exb Date: Sun, 9 Oct 2022 12:55:57 +0200 Subject: [PATCH] TestMI: updated threading model. Part of #1346 --- plugins/samplemimo/testmi/testmi.cpp | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/plugins/samplemimo/testmi/testmi.cpp b/plugins/samplemimo/testmi/testmi.cpp index 38daa771c..0bb04e505 100644 --- a/plugins/samplemimo/testmi/testmi.cpp +++ b/plugins/samplemimo/testmi/testmi.cpp @@ -86,13 +86,13 @@ void TestMI::init() bool TestMI::startRx() { - qDebug("TestMI::startRx"); QMutexLocker mutexLocker(&m_mutex); if (m_running) { - stopRx(); + return true; } + qDebug("TestMI::startRx"); m_testSourceWorkers.push_back(new TestMIWorker(&m_sampleMIFifo, 0)); m_testSourceWorkerThreads.push_back(new QThread()); m_testSourceWorkers.back()->moveToThread(m_testSourceWorkerThreads.back()); @@ -104,10 +104,10 @@ bool TestMI::startRx() m_testSourceWorkers.back()->setSamplerate(m_settings.m_streams[1].m_sampleRate); startWorkers(); + m_running = true; mutexLocker.unlock(); applySettings(m_settings, true); - m_running = true; return true; } @@ -120,22 +120,18 @@ bool TestMI::startTx() void TestMI::stopRx() { - qDebug("TestMI::stopRx"); QMutexLocker mutexLocker(&m_mutex); - stopWorkers(); - std::vector::iterator itW = m_testSourceWorkers.begin(); - std::vector::iterator itT = m_testSourceWorkerThreads.begin(); - - for (; (itW != m_testSourceWorkers.end()) && (itT != m_testSourceWorkerThreads.end()); ++itW, ++itT) - { - (*itW)->deleteLater(); - delete (*itT); + if (!m_running) { + return; } + qDebug("TestMI::stopRx"); + m_running = false; + stopWorkers(); + m_testSourceWorkers.clear(); m_testSourceWorkerThreads.clear(); - m_running = false; } void TestMI::stopTx() @@ -150,6 +146,8 @@ void TestMI::startWorkers() for (; (itW != m_testSourceWorkers.end()) && (itT != m_testSourceWorkerThreads.end()); ++itW, ++itT) { + QObject::connect(*itT, &QThread::finished, *itW, &QObject::deleteLater); + QObject::connect(*itT, &QThread::finished, *itT, &QThread::deleteLater); (*itW)->startWork(); (*itT)->start(); }