From e32e687fe8b1c4c61cef4ceb46113c4e31262c10 Mon Sep 17 00:00:00 2001 From: vsonnier Date: Mon, 14 Aug 2017 09:10:24 +0200 Subject: [PATCH] Make IOThreads terminate() fully non-blocking and misc. - Thanks to timed-pop() usage, it is no longer needed to nudge queues with dummy to wake them - Less bad luck to be stuck there - Misc: leave the trace about the audio thread staturation, useful despite it raises some alarm among users... --- src/audio/AudioThread.cpp | 3 --- src/demod/DemodulatorPreThread.cpp | 10 +--------- src/demod/DemodulatorThread.cpp | 8 ++------ src/demod/DemodulatorWorkerThread.cpp | 2 -- src/demod/DemodulatorWorkerThread.h | 2 -- src/sdr/SDRPostThread.cpp | 3 --- 6 files changed, 3 insertions(+), 25 deletions(-) diff --git a/src/audio/AudioThread.cpp b/src/audio/AudioThread.cpp index dec6450..57f8d5b 100644 --- a/src/audio/AudioThread.cpp +++ b/src/audio/AudioThread.cpp @@ -476,9 +476,6 @@ void AudioThread::run() { void AudioThread::terminate() { IOThread::terminate(); - AudioThreadCommand endCond; // push an empty input to bump the queue - //VSO: blocking push - cmdQueue.push(endCond); } bool AudioThread::isActive() { diff --git a/src/demod/DemodulatorPreThread.cpp b/src/demod/DemodulatorPreThread.cpp index f34f78c..415c16f 100644 --- a/src/demod/DemodulatorPreThread.cpp +++ b/src/demod/DemodulatorPreThread.cpp @@ -348,18 +348,10 @@ int DemodulatorPreThread::getAudioSampleRate() { void DemodulatorPreThread::terminate() { - //make non-blocking calls to be sure threads are flagged for termination before attempting the blocking calls. + //make non-blocking calls to be sure threads are flagged for termination. IOThread::terminate(); workerThread->terminate(); - DemodulatorThreadIQDataPtr inp(new DemodulatorThreadIQData); // push dummy to nudge queue - //VSO: blocking push : - iqInputQueue->push(inp); - - DemodulatorWorkerThreadCommand command; - //VSO: blocking push : - workerQueue->push(command); - //wait blocking for termination here, it could be long with lots of modems and we MUST terminate properly, //else better kill the whole application... workerThread->isTerminated(5000); diff --git a/src/demod/DemodulatorThread.cpp b/src/demod/DemodulatorThread.cpp index f4e84f2..8c3ccc6 100644 --- a/src/demod/DemodulatorThread.cpp +++ b/src/demod/DemodulatorThread.cpp @@ -313,8 +313,8 @@ void DemodulatorThread::run() { if (!muted.load() && (!wxGetApp().getSoloMode() || (demodInstance == wxGetApp().getDemodMgr().getLastActiveDemodulator()))) { //non-blocking push needed for audio out if (!audioOutputQueue->try_push(ati)) { - //Comment this trace, it creates to many false alarms :) - //std::cout << "DemodulatorThread::run() cannot push ati into audioOutputQueue, is full !" << std::endl; + + std::cout << "DemodulatorThread::run() cannot push ati into audioOutputQueue, is full !" << std::endl; std::this_thread::yield(); } } @@ -348,10 +348,6 @@ void DemodulatorThread::run() { void DemodulatorThread::terminate() { IOThread::terminate(); - DemodulatorThreadPostIQDataPtr inp(new DemodulatorThreadPostIQData); // push dummy to nudge queue - - //VSO: blocking push - iqInputQueue->push(inp); } bool DemodulatorThread::isMuted() { diff --git a/src/demod/DemodulatorWorkerThread.cpp b/src/demod/DemodulatorWorkerThread.cpp index 863065f..a2bd35d 100644 --- a/src/demod/DemodulatorWorkerThread.cpp +++ b/src/demod/DemodulatorWorkerThread.cpp @@ -116,6 +116,4 @@ void DemodulatorWorkerThread::run() { void DemodulatorWorkerThread::terminate() { IOThread::terminate(); - DemodulatorWorkerThreadCommand inp; // push dummy to nudge queue - commandQueue->push(inp); } diff --git a/src/demod/DemodulatorWorkerThread.h b/src/demod/DemodulatorWorkerThread.h index 54b2899..a4c3488 100644 --- a/src/demod/DemodulatorWorkerThread.h +++ b/src/demod/DemodulatorWorkerThread.h @@ -32,8 +32,6 @@ public: msresamp_crcf iqResampler; double iqResampleRatio; - - DemodulatorThread *demodThread; long long sampleRate; unsigned int bandwidth; diff --git a/src/sdr/SDRPostThread.cpp b/src/sdr/SDRPostThread.cpp index 0a286bf..a332bcb 100644 --- a/src/sdr/SDRPostThread.cpp +++ b/src/sdr/SDRPostThread.cpp @@ -235,9 +235,6 @@ void SDRPostThread::run() { void SDRPostThread::terminate() { IOThread::terminate(); - SDRThreadIQDataPtr dummy(new SDRThreadIQData); - //VSO: blocking push - iqDataInQueue->push(dummy); } void SDRPostThread::runSingleCH(SDRThreadIQData *data_in) {