diff --git a/src/IOThread.cpp b/src/IOThread.cpp index 3a93e95..c9178c0 100644 --- a/src/IOThread.cpp +++ b/src/IOThread.cpp @@ -10,6 +10,7 @@ IOThread::~IOThread() { #ifdef __APPLE__ void *IOThread::threadMain() { + terminated.store(false); run(); return this; }; @@ -19,6 +20,7 @@ void *IOThread::pthread_helper(void *context) { }; #else void IOThread::threadMain() { + terminated.store(false); run(); }; #endif diff --git a/src/IOThread.h b/src/IOThread.h index dc76267..0b06f0a 100644 --- a/src/IOThread.h +++ b/src/IOThread.h @@ -71,7 +71,7 @@ private: class IOThread { public: IOThread(); - ~IOThread(); + virtual ~IOThread(); static void *pthread_helper(void *context); diff --git a/src/demod/DemodulatorInstance.cpp b/src/demod/DemodulatorInstance.cpp index 38f1bb4..75b6441 100644 --- a/src/demod/DemodulatorInstance.cpp +++ b/src/demod/DemodulatorInstance.cpp @@ -25,8 +25,13 @@ DemodulatorInstance::DemodulatorInstance() : threadQueueNotify = new DemodulatorThreadCommandQueue; threadQueueControl = new DemodulatorThreadControlCommandQueue; - demodulatorPreThread = new DemodulatorPreThread(threadQueueDemod, threadQueuePostDemod, threadQueueControl, threadQueueNotify); - demodulatorPreThread->setCommandQueue(threadQueueCommand); + demodulatorPreThread = new DemodulatorPreThread(); + demodulatorPreThread->setInputQueue("IQDataInput",threadQueueDemod); + demodulatorPreThread->setOutputQueue("IQDataOut",threadQueuePostDemod); + demodulatorPreThread->setInputQueue("ControlQueue",threadQueueControl); + demodulatorPreThread->setOutputQueue("NotifyQueue",threadQueueNotify); + demodulatorPreThread->setInputQueue("CommandQueue",threadQueueCommand); + demodulatorThread = new DemodulatorThread(threadQueuePostDemod, threadQueueControl, threadQueueNotify); audioInputQueue = new AudioThreadInputQueue; diff --git a/src/demod/DemodulatorPreThread.cpp b/src/demod/DemodulatorPreThread.cpp index eb9958c..1129e01 100644 --- a/src/demod/DemodulatorPreThread.cpp +++ b/src/demod/DemodulatorPreThread.cpp @@ -8,11 +8,7 @@ #include "DemodulatorPreThread.h" #include "CubicSDR.h" -DemodulatorPreThread::DemodulatorPreThread(DemodulatorThreadInputQueue* iqInputQueue, DemodulatorThreadPostInputQueue* iqOutputQueue, - DemodulatorThreadControlCommandQueue *threadQueueControl, DemodulatorThreadCommandQueue* threadQueueNotify) : IOThread(), - iqInputQueue(iqInputQueue), iqOutputQueue(iqOutputQueue), audioResampler(NULL), stereoResampler(NULL), iqResampleRatio( - 1), audioResampleRatio(1), firStereoRight(NULL), firStereoLeft(NULL), iirStereoPilot(NULL), iqResampler(NULL), commandQueue(NULL), threadQueueNotify(threadQueueNotify), threadQueueControl( - threadQueueControl) { +DemodulatorPreThread::DemodulatorPreThread() : IOThread(), iqResampler(NULL), iqResampleRatio(1), audioResampler(NULL), stereoResampler(NULL), audioResampleRatio(1), firStereoLeft(NULL), firStereoRight(NULL), iirStereoPilot(NULL) { initialized.store(false); freqShifter = nco_crcf_create(LIQUID_VCO); @@ -21,8 +17,6 @@ DemodulatorPreThread::DemodulatorPreThread(DemodulatorThreadInputQueue* iqInputQ workerQueue = new DemodulatorThreadWorkerCommandQueue; workerResults = new DemodulatorThreadWorkerResultQueue; workerThread = new DemodulatorWorkerThread(workerQueue, workerResults); - - t_Worker = new std::thread(&DemodulatorWorkerThread::threadMain, workerThread); } void DemodulatorPreThread::initialize() { @@ -93,8 +87,16 @@ void DemodulatorPreThread::run() { std::cout << "Demodulator preprocessor thread started.." << std::endl; + t_Worker = new std::thread(&DemodulatorWorkerThread::threadMain, workerThread); + ReBuffer buffers; + DemodulatorThreadInputQueue* iqInputQueue = (DemodulatorThreadInputQueue*)getInputQueue("IQDataInput"); + DemodulatorThreadPostInputQueue* iqOutputQueue = (DemodulatorThreadPostInputQueue*)getOutputQueue("IQDataOut"); + DemodulatorThreadControlCommandQueue *threadQueueControl = (DemodulatorThreadControlCommandQueue *)getInputQueue("ControlQueue"); + DemodulatorThreadCommandQueue* threadQueueNotify = (DemodulatorThreadCommandQueue*)getOutputQueue("NotifyQueue"); + DemodulatorThreadCommandQueue* commandQueue = ( DemodulatorThreadCommandQueue*)getInputQueue("CommandQueue"); + std::vector in_buf_data; std::vector out_buf_data; // liquid_float_complex carrySample; // Keep the stream count even to simplify some demod operations @@ -307,7 +309,13 @@ void DemodulatorPreThread::run() { } buffers.purge(); - + + DemodulatorThreadIQData *inp = new DemodulatorThreadIQData; // push dummy to nudge queue + iqInputQueue->push(inp); + workerThread->terminate(); + t_Worker->detach(); + delete t_Worker; + DemodulatorThreadCommand tCmd(DemodulatorThreadCommand::DEMOD_THREAD_CMD_DEMOD_PREPROCESS_TERMINATED); tCmd.context = this; threadQueueNotify->push(tCmd); @@ -316,9 +324,4 @@ void DemodulatorPreThread::run() { void DemodulatorPreThread::terminate() { terminated = true; - DemodulatorThreadIQData *inp = new DemodulatorThreadIQData; // push dummy to nudge queue - iqInputQueue->push(inp); - workerThread->terminate(); - t_Worker->detach(); - delete t_Worker; } diff --git a/src/demod/DemodulatorPreThread.h b/src/demod/DemodulatorPreThread.h index 6e3585a..5088d55 100644 --- a/src/demod/DemodulatorPreThread.h +++ b/src/demod/DemodulatorPreThread.h @@ -10,20 +10,11 @@ class DemodulatorPreThread : public IOThread { public: - DemodulatorPreThread(DemodulatorThreadInputQueue* iqInputQueue, DemodulatorThreadPostInputQueue* iqOutputQueue, - DemodulatorThreadControlCommandQueue *threadQueueControl, DemodulatorThreadCommandQueue* threadQueueNotify); + DemodulatorPreThread(); ~DemodulatorPreThread(); void run(); - void setCommandQueue(DemodulatorThreadCommandQueue *tQueue) { - commandQueue = tQueue; - } - - void setDemodulatorControlQueue(DemodulatorThreadControlCommandQueue *tQueue) { - threadQueueControl = tQueue; - } - DemodulatorThreadParameters &getParams() { return params; } @@ -42,10 +33,6 @@ public: #endif protected: - DemodulatorThreadInputQueue* iqInputQueue; - DemodulatorThreadPostInputQueue* iqOutputQueue; - DemodulatorThreadCommandQueue* commandQueue; - msresamp_crcf iqResampler; double iqResampleRatio; std::vector resampledData; @@ -71,6 +58,4 @@ protected: DemodulatorThreadWorkerCommandQueue *workerQueue; DemodulatorThreadWorkerResultQueue *workerResults; - DemodulatorThreadCommandQueue* threadQueueNotify; - DemodulatorThreadControlCommandQueue *threadQueueControl; };