Fix demodulator termination / thread lock

This commit is contained in:
Charles J. Cliffe 2015-01-11 20:26:51 -05:00
parent e7b22bd186
commit 2b6da304ef
5 changed files with 9 additions and 5 deletions

View File

@ -421,13 +421,12 @@ void AudioThread::threadMain() {
} }
#endif #endif
std::cout << "Audio thread done." << std::endl;
if (threadQueueNotify != NULL) { if (threadQueueNotify != NULL) {
DemodulatorThreadCommand tCmd(DemodulatorThreadCommand::DEMOD_THREAD_CMD_AUDIO_TERMINATED); DemodulatorThreadCommand tCmd(DemodulatorThreadCommand::DEMOD_THREAD_CMD_AUDIO_TERMINATED);
tCmd.context = this; tCmd.context = this;
threadQueueNotify->push(tCmd); threadQueueNotify->push(tCmd);
} }
std::cout << "Audio thread done." << std::endl;
} }
void AudioThread::terminate() { void AudioThread::terminate() {

View File

@ -126,12 +126,14 @@ bool DemodulatorInstance::isTerminated() {
case DemodulatorThreadCommand::DEMOD_THREAD_CMD_AUDIO_TERMINATED: case DemodulatorThreadCommand::DEMOD_THREAD_CMD_AUDIO_TERMINATED:
t_Audio->join(); t_Audio->join();
audioTerminated = true; audioTerminated = true;
delete t_Audio;
break; break;
case DemodulatorThreadCommand::DEMOD_THREAD_CMD_DEMOD_TERMINATED: case DemodulatorThreadCommand::DEMOD_THREAD_CMD_DEMOD_TERMINATED:
#ifdef __APPLE__ #ifdef __APPLE__
pthread_join(t_Demod, NULL); pthread_join(t_Demod, NULL);
#else #else
t_Demod->join(); t_Demod->join();
delete t_Demod;
#endif #endif
demodTerminated = true; demodTerminated = true;
break; break;
@ -140,6 +142,7 @@ bool DemodulatorInstance::isTerminated() {
pthread_join(t_PreDemod, NULL); pthread_join(t_PreDemod, NULL);
#else #else
t_PreDemod->join(); t_PreDemod->join();
delete t_PreDemod;
#endif #endif
preDemodTerminated = true; preDemodTerminated = true;
break; break;

View File

@ -239,10 +239,10 @@ void DemodulatorPreThread::threadMain() {
delete iqDataDel; delete iqDataDel;
} }
std::cout << "Demodulator preprocessor thread done." << std::endl;
DemodulatorThreadCommand tCmd(DemodulatorThreadCommand::DEMOD_THREAD_CMD_DEMOD_PREPROCESS_TERMINATED); DemodulatorThreadCommand tCmd(DemodulatorThreadCommand::DEMOD_THREAD_CMD_DEMOD_PREPROCESS_TERMINATED);
tCmd.context = this; tCmd.context = this;
threadQueueNotify->push(tCmd); threadQueueNotify->push(tCmd);
std::cout << "Demodulator preprocessor thread done." << std::endl;
} }
void DemodulatorPreThread::terminate() { void DemodulatorPreThread::terminate() {
@ -250,4 +250,6 @@ void DemodulatorPreThread::terminate() {
DemodulatorThreadIQData *inp = new DemodulatorThreadIQData; // push dummy to nudge queue DemodulatorThreadIQData *inp = new DemodulatorThreadIQData; // push dummy to nudge queue
iqInputQueue->push(inp); iqInputQueue->push(inp);
workerThread->terminate(); workerThread->terminate();
t_Worker->detach();
delete t_Worker;
} }

View File

@ -406,10 +406,10 @@ void DemodulatorThread::threadMain() {
delete audioDataDel; delete audioDataDel;
} }
std::cout << "Demodulator thread done." << std::endl;
DemodulatorThreadCommand tCmd(DemodulatorThreadCommand::DEMOD_THREAD_CMD_DEMOD_TERMINATED); DemodulatorThreadCommand tCmd(DemodulatorThreadCommand::DEMOD_THREAD_CMD_DEMOD_TERMINATED);
tCmd.context = this; tCmd.context = this;
threadQueueNotify->push(tCmd); threadQueueNotify->push(tCmd);
std::cout << "Demodulator thread done." << std::endl;
} }
void DemodulatorThread::setVisualOutputQueue(DemodulatorThreadOutputQueue *tQueue) { void DemodulatorThread::setVisualOutputQueue(DemodulatorThreadOutputQueue *tQueue) {

View File

@ -31,7 +31,7 @@ void DemodulatorWorkerThread::threadMain() {
done = commandQueue->empty(); done = commandQueue->empty();
} }
if (filterChanged) { if (filterChanged && !terminated) {
DemodulatorWorkerThreadResult result(DemodulatorWorkerThreadResult::DEMOD_WORKER_THREAD_RESULT_FILTERS); DemodulatorWorkerThreadResult result(DemodulatorWorkerThreadResult::DEMOD_WORKER_THREAD_RESULT_FILTERS);
result.iqResampleRatio = (double) (filterCommand.bandwidth) / (double) filterCommand.sampleRate; result.iqResampleRatio = (double) (filterCommand.bandwidth) / (double) filterCommand.sampleRate;