From b2e8cf0482f73cea6fffe6dfe6f467e5cea2abc8 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Thu, 22 Jan 2015 23:41:33 -0500 Subject: [PATCH] Demod worker lock-on-remove fix --- src/CubicSDR.cpp | 1 + src/demod/DemodulatorInstance.cpp | 6 +++--- src/demod/DemodulatorThread.cpp | 4 ++++ src/demod/DemodulatorWorkerThread.cpp | 6 +++++- src/sdr/SDRPostThread.cpp | 4 ++++ 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/CubicSDR.cpp b/src/CubicSDR.cpp index cbd6cc6..4f428ca 100644 --- a/src/CubicSDR.cpp +++ b/src/CubicSDR.cpp @@ -185,6 +185,7 @@ void CubicSDR::removeDemodulator(DemodulatorInstance *demod) { if (!demod) { return; } + demod->setActive(false); sdrPostThread->removeDemodulator(demod); } diff --git a/src/demod/DemodulatorInstance.cpp b/src/demod/DemodulatorInstance.cpp index 896b10c..ccbb3d1 100644 --- a/src/demod/DemodulatorInstance.cpp +++ b/src/demod/DemodulatorInstance.cpp @@ -126,14 +126,14 @@ bool DemodulatorInstance::isTerminated() { case DemodulatorThreadCommand::DEMOD_THREAD_CMD_AUDIO_TERMINATED: t_Audio->join(); audioTerminated = true; -// delete t_Audio; + delete t_Audio; break; case DemodulatorThreadCommand::DEMOD_THREAD_CMD_DEMOD_TERMINATED: #ifdef __APPLE__ pthread_join(t_Demod, NULL); #else t_Demod->join(); -// delete t_Demod; + delete t_Demod; #endif demodTerminated = true; break; @@ -142,7 +142,7 @@ bool DemodulatorInstance::isTerminated() { pthread_join(t_PreDemod, NULL); #else t_PreDemod->join(); -// delete t_PreDemod; + delete t_PreDemod; #endif preDemodTerminated = true; break; diff --git a/src/demod/DemodulatorThread.cpp b/src/demod/DemodulatorThread.cpp index a0642f2..9f853f6 100644 --- a/src/demod/DemodulatorThread.cpp +++ b/src/demod/DemodulatorThread.cpp @@ -409,6 +409,10 @@ void DemodulatorThread::threadMain() { delete audioDataDel; } + if (audioVisOutputQueue && !audioVisOutputQueue->empty()) { + AudioThreadInput *dummy_vis; + audioVisOutputQueue->pop(dummy_vis); + } delete ati_vis; DemodulatorThreadCommand tCmd(DemodulatorThreadCommand::DEMOD_THREAD_CMD_DEMOD_TERMINATED); diff --git a/src/demod/DemodulatorWorkerThread.cpp b/src/demod/DemodulatorWorkerThread.cpp index 58bc1de..9fd228c 100644 --- a/src/demod/DemodulatorWorkerThread.cpp +++ b/src/demod/DemodulatorWorkerThread.cpp @@ -24,6 +24,9 @@ void DemodulatorWorkerThread::threadMain() { commandQueue->pop(command); switch (command.cmd) { case DemodulatorWorkerThreadCommand::DEMOD_WORKER_THREAD_CMD_BUILD_FILTERS: + if (!filterCommand.bandwidth || !filterCommand.audioSampleRate) { + break; + } filterChanged = true; filterCommand = command; break; @@ -32,13 +35,14 @@ void DemodulatorWorkerThread::threadMain() { } done = commandQueue->empty(); } + if (filterChanged && !terminated) { DemodulatorWorkerThreadResult result(DemodulatorWorkerThreadResult::DEMOD_WORKER_THREAD_RESULT_FILTERS); result.iqResampleRatio = (double) (filterCommand.bandwidth) / (double) filterCommand.sampleRate; result.audioResamplerRatio = (double) (filterCommand.audioSampleRate) / (double) filterCommand.bandwidth; - + float As = 60.0f; // stop-band attenuation [dB] result.iqResampler = msresamp_crcf_create(result.iqResampleRatio, As); diff --git a/src/sdr/SDRPostThread.cpp b/src/sdr/SDRPostThread.cpp index ac54011..c8b1037 100644 --- a/src/sdr/SDRPostThread.cpp +++ b/src/sdr/SDRPostThread.cpp @@ -208,6 +208,10 @@ void SDRPostThread::threadMain() { // std::lock_guard < std::mutex > lock(demodDataDel->m_mutex); // delete demodDataDel; } + if (iqVisualQueue.load() && !iqVisualQueue.load()->empty()) { + DemodulatorThreadIQData *visualDataDummy; + iqVisualQueue.load()->pop(visualDataDummy); + } delete visualDataOut;