From 2b6da304ef2cdea81f75a7d20baab81aeb8f3f06 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Sun, 11 Jan 2015 20:26:51 -0500 Subject: [PATCH] Fix demodulator termination / thread lock --- src/audio/AudioThread.cpp | 3 +-- src/demod/DemodulatorInstance.cpp | 3 +++ src/demod/DemodulatorPreThread.cpp | 4 +++- src/demod/DemodulatorThread.cpp | 2 +- src/demod/DemodulatorWorkerThread.cpp | 2 +- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/audio/AudioThread.cpp b/src/audio/AudioThread.cpp index 701ca66..f41d506 100644 --- a/src/audio/AudioThread.cpp +++ b/src/audio/AudioThread.cpp @@ -421,13 +421,12 @@ void AudioThread::threadMain() { } #endif - std::cout << "Audio thread done." << std::endl; - if (threadQueueNotify != NULL) { DemodulatorThreadCommand tCmd(DemodulatorThreadCommand::DEMOD_THREAD_CMD_AUDIO_TERMINATED); tCmd.context = this; threadQueueNotify->push(tCmd); } + std::cout << "Audio thread done." << std::endl; } void AudioThread::terminate() { diff --git a/src/demod/DemodulatorInstance.cpp b/src/demod/DemodulatorInstance.cpp index 3981658..e82c8af 100644 --- a/src/demod/DemodulatorInstance.cpp +++ b/src/demod/DemodulatorInstance.cpp @@ -126,12 +126,14 @@ bool DemodulatorInstance::isTerminated() { case DemodulatorThreadCommand::DEMOD_THREAD_CMD_AUDIO_TERMINATED: t_Audio->join(); audioTerminated = true; + 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; #endif demodTerminated = true; break; @@ -140,6 +142,7 @@ bool DemodulatorInstance::isTerminated() { pthread_join(t_PreDemod, NULL); #else t_PreDemod->join(); + delete t_PreDemod; #endif preDemodTerminated = true; break; diff --git a/src/demod/DemodulatorPreThread.cpp b/src/demod/DemodulatorPreThread.cpp index b42ffcc..b412e0d 100644 --- a/src/demod/DemodulatorPreThread.cpp +++ b/src/demod/DemodulatorPreThread.cpp @@ -239,10 +239,10 @@ void DemodulatorPreThread::threadMain() { delete iqDataDel; } - std::cout << "Demodulator preprocessor thread done." << std::endl; DemodulatorThreadCommand tCmd(DemodulatorThreadCommand::DEMOD_THREAD_CMD_DEMOD_PREPROCESS_TERMINATED); tCmd.context = this; threadQueueNotify->push(tCmd); + std::cout << "Demodulator preprocessor thread done." << std::endl; } void DemodulatorPreThread::terminate() { @@ -250,4 +250,6 @@ void DemodulatorPreThread::terminate() { DemodulatorThreadIQData *inp = new DemodulatorThreadIQData; // push dummy to nudge queue iqInputQueue->push(inp); workerThread->terminate(); + t_Worker->detach(); + delete t_Worker; } diff --git a/src/demod/DemodulatorThread.cpp b/src/demod/DemodulatorThread.cpp index 99a3cb9..8ed1b20 100644 --- a/src/demod/DemodulatorThread.cpp +++ b/src/demod/DemodulatorThread.cpp @@ -406,10 +406,10 @@ void DemodulatorThread::threadMain() { delete audioDataDel; } - std::cout << "Demodulator thread done." << std::endl; DemodulatorThreadCommand tCmd(DemodulatorThreadCommand::DEMOD_THREAD_CMD_DEMOD_TERMINATED); tCmd.context = this; threadQueueNotify->push(tCmd); + std::cout << "Demodulator thread done." << std::endl; } void DemodulatorThread::setVisualOutputQueue(DemodulatorThreadOutputQueue *tQueue) { diff --git a/src/demod/DemodulatorWorkerThread.cpp b/src/demod/DemodulatorWorkerThread.cpp index 4037b04..302fb14 100644 --- a/src/demod/DemodulatorWorkerThread.cpp +++ b/src/demod/DemodulatorWorkerThread.cpp @@ -31,7 +31,7 @@ void DemodulatorWorkerThread::threadMain() { done = commandQueue->empty(); } - if (filterChanged) { + if (filterChanged && !terminated) { DemodulatorWorkerThreadResult result(DemodulatorWorkerThreadResult::DEMOD_WORKER_THREAD_RESULT_FILTERS); result.iqResampleRatio = (double) (filterCommand.bandwidth) / (double) filterCommand.sampleRate;