Fix demodulator init race

This commit is contained in:
Charles J. Cliffe 2015-11-20 21:41:57 -05:00
parent 7e856988a2
commit 703e281d76
2 changed files with 12 additions and 7 deletions

View File

@ -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);
}

View File

@ -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;