From 50bfb251f8defc56c5a6b80ec570b29fa18d9a1e Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Tue, 7 Jun 2016 20:36:59 -0400 Subject: [PATCH] Attempt to clean up any buffers that weren't used on terminate, still one hanging around.. --- src/audio/AudioThread.cpp | 8 ++++++++ src/demod/DemodulatorPreThread.cpp | 5 +++++ src/demod/DemodulatorThread.cpp | 11 +++++++++++ src/util/ThreadQueue.h | 3 ++- 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/audio/AudioThread.cpp b/src/audio/AudioThread.cpp index 62cec69..c4152de 100644 --- a/src/audio/AudioThread.cpp +++ b/src/audio/AudioThread.cpp @@ -421,6 +421,14 @@ void AudioThread::terminate() { terminated = true; AudioThreadCommand endCond; // push an empty input to bump the queue cmdQueue.push(endCond); + + while (!inputQueue->empty()) { // flush queue + AudioThreadInput *dummy; + inputQueue->pop(dummy); + if (dummy) { + dummy->decRefCount(); + } + } } bool AudioThread::isActive() { diff --git a/src/demod/DemodulatorPreThread.cpp b/src/demod/DemodulatorPreThread.cpp index 31f9dfc..e1a438c 100644 --- a/src/demod/DemodulatorPreThread.cpp +++ b/src/demod/DemodulatorPreThread.cpp @@ -271,6 +271,11 @@ void DemodulatorPreThread::run() { } } + while (!iqOutputQueue->empty()) { + DemodulatorThreadPostIQData *tmp; + iqOutputQueue->pop(tmp); + tmp->decRefCount(); + } buffers.purge(); DemodulatorThreadCommand tCmd(DemodulatorThreadCommand::DEMOD_THREAD_CMD_DEMOD_PREPROCESS_TERMINATED); diff --git a/src/demod/DemodulatorThread.cpp b/src/demod/DemodulatorThread.cpp index 254aa68..0ef3bb1 100644 --- a/src/demod/DemodulatorThread.cpp +++ b/src/demod/DemodulatorThread.cpp @@ -277,6 +277,17 @@ void DemodulatorThread::run() { } // end while !terminated + // Purge any unused inputs + while (!iqInputQueue->empty()) { + DemodulatorThreadPostIQData *inp; + iqInputQueue->pop(inp); + inp->setRefCount(0); + } + while (!audioOutputQueue->empty()) { + AudioThreadInput *ati; + audioOutputQueue->pop(ati); + ati->setRefCount(0); + } outputBuffers.purge(); //Guard the cleanup of audioVisOutputQueue properly. diff --git a/src/util/ThreadQueue.h b/src/util/ThreadQueue.h index e69265c..4d1f901 100644 --- a/src/util/ThreadQueue.h +++ b/src/util/ThreadQueue.h @@ -231,8 +231,9 @@ public: /** * Remove any items in the queue. */ - void flush() const { + void flush() { std::lock_guard < std::mutex > lock(m_mutex); + m_queue = std::queue(); std::queue emptyQueue; std::swap(m_queue, emptyQueue); }