mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2026-07-30 05:54:07 -04:00
THREAD_CLEAN: Clearly distinguish between a request to stop by terminate() from the actual termination isTerminated()
This commit is contained in:
@@ -35,10 +35,7 @@ DemodulatorInstance::DemodulatorInstance() {
|
||||
#if ENABLE_DIGITAL_LAB
|
||||
activeOutput = nullptr;
|
||||
#endif
|
||||
terminated.store(true);
|
||||
demodTerminated.store(true);
|
||||
audioTerminated.store(true);
|
||||
preDemodTerminated.store(true);
|
||||
|
||||
active.store(false);
|
||||
squelch.store(false);
|
||||
muted.store(false);
|
||||
@@ -125,7 +122,6 @@ void DemodulatorInstance::run() {
|
||||
#endif
|
||||
|
||||
active = true;
|
||||
audioTerminated = demodTerminated = preDemodTerminated = terminated = false;
|
||||
|
||||
}
|
||||
|
||||
@@ -163,7 +159,7 @@ bool DemodulatorInstance::isTerminated() {
|
||||
case DemodulatorThreadCommand::DEMOD_THREAD_CMD_AUDIO_TERMINATED:
|
||||
if (t_Audio) {
|
||||
t_Audio->join();
|
||||
audioTerminated = true;
|
||||
|
||||
delete t_Audio;
|
||||
t_Audio = nullptr;
|
||||
}
|
||||
@@ -183,7 +179,6 @@ bool DemodulatorInstance::isTerminated() {
|
||||
closeOutput();
|
||||
}
|
||||
#endif
|
||||
demodTerminated = true;
|
||||
break;
|
||||
case DemodulatorThreadCommand::DEMOD_THREAD_CMD_DEMOD_PREPROCESS_TERMINATED:
|
||||
if (t_PreDemod) {
|
||||
@@ -193,7 +188,6 @@ bool DemodulatorInstance::isTerminated() {
|
||||
t_PreDemod->join();
|
||||
delete t_PreDemod;
|
||||
#endif
|
||||
preDemodTerminated = true;
|
||||
t_PreDemod = nullptr;
|
||||
}
|
||||
break;
|
||||
@@ -202,7 +196,12 @@ bool DemodulatorInstance::isTerminated() {
|
||||
}
|
||||
}
|
||||
|
||||
terminated = audioTerminated && demodTerminated && preDemodTerminated;
|
||||
//
|
||||
bool audioTerminated = audioThread->isTerminated();
|
||||
bool demodTerminated = demodulatorThread->isTerminated();
|
||||
bool preDemodTerminated = demodulatorPreThread->isTerminated();
|
||||
|
||||
bool terminated = audioTerminated && demodTerminated && preDemodTerminated;
|
||||
|
||||
return terminated;
|
||||
}
|
||||
|
||||
@@ -141,10 +141,7 @@ private:
|
||||
std::atomic<std::string *> label; //
|
||||
// User editable buffer, 16 bit string.
|
||||
std::atomic<std::wstring *> user_label;
|
||||
std::atomic_bool terminated; //
|
||||
std::atomic_bool demodTerminated; //
|
||||
std::atomic_bool audioTerminated; //
|
||||
std::atomic_bool preDemodTerminated;
|
||||
|
||||
std::atomic_bool active;
|
||||
std::atomic_bool squelch;
|
||||
std::atomic_bool muted;
|
||||
|
||||
@@ -65,7 +65,7 @@ void DemodulatorPreThread::run() {
|
||||
|
||||
t_Worker = new std::thread(&DemodulatorWorkerThread::threadMain, workerThread);
|
||||
|
||||
while (!terminated) {
|
||||
while (!stopping) {
|
||||
DemodulatorThreadIQData *inp;
|
||||
iqInputQueue->pop(inp);
|
||||
|
||||
@@ -211,7 +211,7 @@ void DemodulatorPreThread::run() {
|
||||
|
||||
inp->decRefCount();
|
||||
|
||||
if (!terminated && !workerResults->empty()) {
|
||||
if (!stopping && !workerResults->empty()) {
|
||||
while (!workerResults->empty()) {
|
||||
DemodulatorWorkerThreadResult result;
|
||||
workerResults->pop(result);
|
||||
@@ -341,7 +341,7 @@ int DemodulatorPreThread::getAudioSampleRate() {
|
||||
}
|
||||
|
||||
void DemodulatorPreThread::terminate() {
|
||||
terminated = true;
|
||||
IOThread::terminate();
|
||||
DemodulatorThreadIQData *inp = new DemodulatorThreadIQData; // push dummy to nudge queue
|
||||
iqInputQueue->push(inp);
|
||||
DemodulatorWorkerThreadCommand command(DemodulatorWorkerThreadCommand::DEMOD_WORKER_THREAD_CMD_NULL);
|
||||
|
||||
@@ -15,7 +15,7 @@ public:
|
||||
DemodulatorPreThread(DemodulatorInstance *parent);
|
||||
~DemodulatorPreThread();
|
||||
|
||||
void run();
|
||||
virtual void run();
|
||||
|
||||
void setDemodType(std::string demodType);
|
||||
std::string getDemodType();
|
||||
@@ -34,7 +34,7 @@ public:
|
||||
|
||||
bool isInitialized();
|
||||
|
||||
void terminate();
|
||||
virtual void terminate();
|
||||
|
||||
Modem *getModem();
|
||||
ModemKit *getModemKit();
|
||||
|
||||
@@ -73,7 +73,7 @@ void DemodulatorThread::run() {
|
||||
|
||||
ModemIQData modemData;
|
||||
|
||||
while (!terminated) {
|
||||
while (!stopping) {
|
||||
DemodulatorThreadPostIQData *inp;
|
||||
iqInputQueue->pop(inp);
|
||||
// std::lock_guard < std::mutex > lock(inp->m_mutex);
|
||||
@@ -271,7 +271,7 @@ void DemodulatorThread::run() {
|
||||
|
||||
inp->decRefCount();
|
||||
}
|
||||
// end while !terminated
|
||||
// end while !stopping
|
||||
|
||||
// Purge any unused inputs
|
||||
while (!iqInputQueue->empty()) {
|
||||
@@ -301,7 +301,7 @@ void DemodulatorThread::run() {
|
||||
}
|
||||
|
||||
void DemodulatorThread::terminate() {
|
||||
terminated = true;
|
||||
IOThread::terminate();
|
||||
DemodulatorThreadPostIQData *inp = new DemodulatorThreadPostIQData; // push dummy to nudge queue
|
||||
iqInputQueue->push(inp);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ void DemodulatorWorkerThread::run() {
|
||||
commandQueue = static_cast<DemodulatorThreadWorkerCommandQueue *>(getInputQueue("WorkerCommandQueue"));
|
||||
resultQueue = static_cast<DemodulatorThreadWorkerResultQueue *>(getOutputQueue("WorkerResultQueue"));
|
||||
|
||||
while (!terminated) {
|
||||
while (!stopping) {
|
||||
bool filterChanged = false;
|
||||
bool makeDemod = false;
|
||||
DemodulatorWorkerThreadCommand filterCommand, demodCommand;
|
||||
@@ -41,7 +41,7 @@ void DemodulatorWorkerThread::run() {
|
||||
done = commandQueue->empty();
|
||||
}
|
||||
|
||||
if ((makeDemod || filterChanged) && !terminated) {
|
||||
if ((makeDemod || filterChanged) && !stopping) {
|
||||
DemodulatorWorkerThreadResult result(DemodulatorWorkerThreadResult::DEMOD_WORKER_THREAD_RESULT_FILTERS);
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ void DemodulatorWorkerThread::run() {
|
||||
}
|
||||
|
||||
void DemodulatorWorkerThread::terminate() {
|
||||
terminated = true;
|
||||
IOThread::terminate();
|
||||
DemodulatorWorkerThreadCommand inp; // push dummy to nudge queue
|
||||
commandQueue->push(inp);
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ public:
|
||||
DemodulatorWorkerThread();
|
||||
~DemodulatorWorkerThread();
|
||||
|
||||
void run();
|
||||
virtual void run();
|
||||
|
||||
void setCommandQueue(DemodulatorThreadWorkerCommandQueue *tQueue) {
|
||||
commandQueue = tQueue;
|
||||
@@ -85,7 +85,7 @@ public:
|
||||
resultQueue = tQueue;
|
||||
}
|
||||
|
||||
void terminate();
|
||||
virtual void terminate();
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user