Add signal handlers for a proper cleanup

Fix locking problem in get_rtlsdr_sample when it waits indefinitely
even when exitflag is non-zero; cleanup the code.
This commit is contained in:
Volo Zyko
2023-06-30 14:12:48 +03:00
parent eacbd21c50
commit 0e9b2b245d
5 changed files with 39 additions and 12 deletions

View File

@@ -121,7 +121,6 @@ getSymbol (dsd_opts * opts, dsd_state * state, int have_sync)
//else cleanup and exit
else
{
if (opts->use_ncurses_terminal == 1) ncursesClose(opts);
cleanupAndExit(opts, state);
}
}
@@ -131,7 +130,10 @@ getSymbol (dsd_opts * opts, dsd_state * state, int have_sync)
#ifdef USE_RTLSDR
// TODO: need to read demodulated stream here
// get_rtlsdr_sample(&sample);
get_rtlsdr_sample(&sample, opts, state);
if (get_rtlsdr_sample(&sample, opts, state) < 0)
{
cleanupAndExit(opts, state);
}
if (opts->monitor_input_audio == 1 && state->lastsynctype == -1 && sample < 32767 && sample > -32767)
{
state->pulse_raw_out_buffer = sample; //steal raw out buffer sample here?
@@ -195,7 +197,6 @@ getSymbol (dsd_opts * opts, dsd_state * state, int have_sync)
{
fprintf (stderr, "Connection to TCP Server Disconnected.\n");
fprintf (stderr, "Closing DSD-FME.\n");
if (opts->use_ncurses_terminal == 1) ncursesClose(opts);
cleanupAndExit(opts, state);
}
@@ -533,7 +534,6 @@ getSymbol (dsd_opts * opts, dsd_state * state, int have_sync)
//else cleanup and exit
else
{
if (opts->use_ncurses_terminal == 1) ncursesClose(opts);
cleanupAndExit(opts, state);
}
}