From 9f5c6746466ac23e3cfe50fffa03930dd968c78b Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Sat, 13 Aug 2016 14:18:41 -0400 Subject: [PATCH] Make sure squelch lock is released on de-activate too --- src/demod/DemodulatorInstance.cpp | 1 + src/demod/DemodulatorThread.cpp | 21 +++++++++++++-------- src/demod/DemodulatorThread.h | 2 ++ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/demod/DemodulatorInstance.cpp b/src/demod/DemodulatorInstance.cpp index 7b770b3..bf3d788 100644 --- a/src/demod/DemodulatorInstance.cpp +++ b/src/demod/DemodulatorInstance.cpp @@ -214,6 +214,7 @@ void DemodulatorInstance::setActive(bool state) { } #endif audioThread->setActive(state); + DemodulatorThread::releaseSquelchLock(this); } else if (!active && state) { #if ENABLE_DIGITAL_LAB if (activeOutput && getModemType() == "digital") { diff --git a/src/demod/DemodulatorThread.cpp b/src/demod/DemodulatorThread.cpp index 63414b1..1bb0edd 100644 --- a/src/demod/DemodulatorThread.cpp +++ b/src/demod/DemodulatorThread.cpp @@ -26,10 +26,7 @@ DemodulatorThread::DemodulatorThread(DemodulatorInstance *parent) } DemodulatorThread::~DemodulatorThread() { - std::lock_guard < std::mutex > lock(squelchLockMutex); - if (squelchLock.load() == demodInstance) { - squelchLock.store(nullptr); - } + releaseSquelchLock(demodInstance); } void DemodulatorThread::onBindOutput(std::string name, ThreadQueueBase *threadQueue) { @@ -208,10 +205,7 @@ void DemodulatorThread::run() { } } else if (squelched && squelchBreak) { - std::lock_guard < std::mutex > lock(squelchLockMutex); - if (squelchLock.load() == demodInstance) { - squelchLock.store(nullptr); - } + releaseSquelchLock(demodInstance); squelchBreak = false; } } @@ -403,3 +397,14 @@ void DemodulatorThread::setSquelchLevel(float signal_level_in) { float DemodulatorThread::getSquelchLevel() { return squelchLevel; } + +bool DemodulatorThread::getSquelchBreak() { + return squelchBreak; +} + +void DemodulatorThread::releaseSquelchLock(DemodulatorInstance *inst) { + std::lock_guard < std::mutex > lock(squelchLockMutex); + if (squelchLock.load() == inst) { + squelchLock.store(nullptr); + } +} \ No newline at end of file diff --git a/src/demod/DemodulatorThread.h b/src/demod/DemodulatorThread.h index 5176c72..c477e7e 100644 --- a/src/demod/DemodulatorThread.h +++ b/src/demod/DemodulatorThread.h @@ -36,6 +36,8 @@ public: float getSquelchLevel(); bool getSquelchBreak(); + + static void releaseSquelchLock(DemodulatorInstance *inst); protected: