From 703e281d76631170d345c0b36379148a91f5ddda Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Fri, 20 Nov 2015 21:41:57 -0500 Subject: [PATCH] Fix demodulator init race --- src/demod/DemodulatorInstance.cpp | 3 ++- src/demod/DemodulatorWorkerThread.cpp | 16 ++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/demod/DemodulatorInstance.cpp b/src/demod/DemodulatorInstance.cpp index 5f73a2e..112b97d 100644 --- a/src/demod/DemodulatorInstance.cpp +++ b/src/demod/DemodulatorInstance.cpp @@ -75,6 +75,7 @@ void DemodulatorInstance::run() { currentFrequency = demodulatorPreThread->getParams().frequency; currentAudioSampleRate = AudioThread::deviceSampleRate[getOutputDevice()]; demodulatorPreThread->getParams().audioSampleRate = currentAudioSampleRate; + setDemodulatorType(demodulatorPreThread->getParams().demodType); t_Audio = new std::thread(&AudioThread::threadMain, audioThread); @@ -101,7 +102,6 @@ void DemodulatorInstance::run() { t_Demod = new std::thread(&DemodulatorThread::threadMain, demodulatorThread); #endif - setDemodulatorType(demodulatorPreThread->getParams().demodType); active = true; audioTerminated = demodTerminated = preDemodTerminated = terminated = false; @@ -289,6 +289,7 @@ void DemodulatorInstance::setDemodulatorType(std::string demod_type_in) { demodulatorPreThread->getParams().demodType = currentDemodType; if (!active) { checkBandwidth(); + demodulatorPreThread->setDemodType(currentDemodType); } else if (demodulatorThread && threadQueueControl) { demodulatorPreThread->setDemodType(currentDemodType); } diff --git a/src/demod/DemodulatorWorkerThread.cpp b/src/demod/DemodulatorWorkerThread.cpp index 5eb7e93..4e63ca5 100644 --- a/src/demod/DemodulatorWorkerThread.cpp +++ b/src/demod/DemodulatorWorkerThread.cpp @@ -19,7 +19,7 @@ void DemodulatorWorkerThread::run() { while (!terminated) { bool filterChanged = false; bool makeDemod = false; - DemodulatorWorkerThreadCommand filterCommand; + DemodulatorWorkerThreadCommand filterCommand, demodCommand; DemodulatorWorkerThreadCommand command; bool done = false; @@ -32,7 +32,7 @@ void DemodulatorWorkerThread::run() { break; case DemodulatorWorkerThreadCommand::DEMOD_WORKER_THREAD_CMD_MAKE_DEMOD: makeDemod = true; - filterCommand = command; + demodCommand = command; break; default: break; @@ -52,15 +52,19 @@ void DemodulatorWorkerThread::run() { } if (makeDemod) { - cModem = Modem::makeModem(filterCommand.demodType); - cModemType = filterCommand.demodType; + cModem = Modem::makeModem(demodCommand.demodType); + cModemType = demodCommand.demodType; } result.modem = cModem; - if (filterCommand.bandwidth && filterCommand.audioSampleRate) { + if (makeDemod && demodCommand.bandwidth && demodCommand.audioSampleRate) { if (cModem != nullptr) { - cModemKit = cModem->buildKit(filterCommand.bandwidth, filterCommand.audioSampleRate); + cModemKit = cModem->buildKit(demodCommand.bandwidth, demodCommand.audioSampleRate); + } else { + cModemKit = nullptr; } + } else if (makeDemod) { + cModemKit = nullptr; } result.modemKit = cModemKit;