diff --git a/fm.c b/fm.c index 150bbaa5..9cd0aef0 100644 --- a/fm.c +++ b/fm.c @@ -65,11 +65,7 @@ void *demod_fm(void *arg){ realtime(); - while(!chan->terminate){ - int rval = downconvert(chan); - if(rval != 0) - break; - + while(downconvert(chan) == 0){ if(power_squelch && squelch_state == 0){ // quick check SNR from raw signal power to save time on variance-based squelch // Variance squelch is still needed to suppress various spurs and QRM @@ -262,6 +258,6 @@ void *demod_fm(void *arg){ chan->output.energy += output_level; if(send_output(chan,baseband,N,false) < 0) break; // no valid output stream; terminate! - } // while(!chan->terminate) + } return NULL; } diff --git a/linear.c b/linear.c index 22581cda..22ae5d0c 100644 --- a/linear.c +++ b/linear.c @@ -56,11 +56,7 @@ void *demod_linear(void *arg){ realtime(); - while(!chan->terminate){ - int rval = downconvert(chan); - if(rval != 0) - break; - + while(downconvert(chan) == 0){ int const N = chan->filter.out.olen; // Number of raw samples in filter output buffer // First pass over sample block. diff --git a/radio.c b/radio.c index d34b612a..5c9aee8e 100644 --- a/radio.c +++ b/radio.c @@ -505,11 +505,10 @@ int downconvert(struct channel *chan){ while(true){ // Should we die? - // Won't work correctly if 0 Hz is outside front end coverage - // Should make this cleaner + // Will be slower if 0 Hz is outside front end coverage because of slow timed wait below + // But at least it will eventually go away if(chan->tune.freq == 0 && chan->lifetime > 0){ - chan->lifetime--; - if(chan->lifetime <= 0){ + if(--chan->lifetime <= 0){ chan->demod_type = -1; // No demodulator return -1; // terminate needed } @@ -547,10 +546,6 @@ int downconvert(struct channel *chan){ // end status changes rather than process zeroes. We must still poll the terminate flag. pthread_mutex_lock(&Frontend.status_mutex); - if(chan->terminate){ - pthread_mutex_unlock(&Frontend.status_mutex); - return -1; - } chan->tune.second_LO = Frontend.frequency - chan->tune.freq; double const freq = chan->tune.doppler + chan->tune.second_LO; // Total logical oscillator frequency if(compute_tuning(Frontend.in.ilen + Frontend.in.impulse_length - 1, diff --git a/radio.h b/radio.h index 8efcdbd2..6c42df57 100644 --- a/radio.h +++ b/radio.h @@ -246,9 +246,6 @@ struct channel { } sap; pthread_t demod_thread; - // Set this flag to ask demod_thread to terminate. - // pthread_cancel() can't be used because we're usually waiting inside of a mutex, and deadlock will occur - bool terminate; float tp1,tp2; // Spare test points that can be read on the status channel }; diff --git a/spectrum.c b/spectrum.c index 92a02b6c..b1122a23 100644 --- a/spectrum.c +++ b/spectrum.c @@ -68,11 +68,7 @@ void *demod_spectrum(void *arg){ set_freq(chan,chan->tune.freq); // retune front end if needed to cover requested bandwidth // Still need to clean up code to force radio freq to be multiple of FFT bin spacing - while(!chan->terminate){ - int rval = downconvert(chan); - if(rval != 0) - break; - + while(downconvert(chan) == 0){ int binp = 0; for(int i=0; i < chan->spectrum.bin_count; i++){ // For each noncoherent integration bin above center freq float p = 0; diff --git a/wfm.c b/wfm.c index 46c6b585..cfc6bcd8 100644 --- a/wfm.c +++ b/wfm.c @@ -112,11 +112,7 @@ void *demod_wfm(void *arg){ realtime(); - while(!chan->terminate){ - int rval = downconvert(chan); - if(rval != 0) - break; - + while(downconvert(chan) == 0){ if(power_squelch && squelch_state == 0){ // quick check SNR from raw signal power to save time on variance-based squelch // Variance squelch is still needed to suppress various spurs and QRM @@ -281,7 +277,7 @@ void *demod_wfm(void *arg){ break; // No output stream! Terminate chan->output.channels = channels_save; } - } // while(!chan->terminate) + } quit:; delete_filter_output(&mono); delete_filter_output(&lminusr);