Continuing to try to work around libusb/librtlsdr problems.
This commit is contained in:
parent
4fb607a826
commit
9deac8d894
22
dump1090.c
22
dump1090.c
|
@ -332,6 +332,10 @@ void rtlsdrCallback(unsigned char *buf, uint32_t len, void *ctx) {
|
||||||
// Lock the data buffer variables before accessing them
|
// Lock the data buffer variables before accessing them
|
||||||
pthread_mutex_lock(&Modes.data_mutex);
|
pthread_mutex_lock(&Modes.data_mutex);
|
||||||
|
|
||||||
|
if (Modes.exit) {
|
||||||
|
rtlsdr_cancel_async(Modes.dev); // ask our caller to exit
|
||||||
|
}
|
||||||
|
|
||||||
Modes.iDataIn &= (MODES_ASYNC_BUF_NUMBER-1); // Just incase!!!
|
Modes.iDataIn &= (MODES_ASYNC_BUF_NUMBER-1); // Just incase!!!
|
||||||
|
|
||||||
// Get the system time for this block
|
// Get the system time for this block
|
||||||
|
@ -437,6 +441,7 @@ void *readerThreadEntryPoint(void *arg) {
|
||||||
if (!Modes.exit) {
|
if (!Modes.exit) {
|
||||||
fprintf(stderr, "Warning: lost the connection to the RTLSDR device.\n");
|
fprintf(stderr, "Warning: lost the connection to the RTLSDR device.\n");
|
||||||
rtlsdr_close(Modes.dev);
|
rtlsdr_close(Modes.dev);
|
||||||
|
Modes.dev = NULL;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
sleep(5);
|
sleep(5);
|
||||||
|
@ -444,6 +449,11 @@ void *readerThreadEntryPoint(void *arg) {
|
||||||
} while (!Modes.exit && modesInitRTLSDR() < 0);
|
} while (!Modes.exit && modesInitRTLSDR() < 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Modes.dev != NULL) {
|
||||||
|
rtlsdr_close(Modes.dev);
|
||||||
|
Modes.dev = NULL;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
readDataFromFile();
|
readDataFromFile();
|
||||||
}
|
}
|
||||||
|
@ -1046,19 +1056,7 @@ int main(int argc, char **argv) {
|
||||||
display_total_stats();
|
display_total_stats();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Modes.filename == NULL) {
|
|
||||||
rtlsdr_cancel_async(Modes.dev); // Cancel rtlsdr_read_async will cause data input thread to terminate cleanly
|
|
||||||
}
|
|
||||||
|
|
||||||
pthread_join(Modes.reader_thread,NULL); // Wait on reader thread exit
|
pthread_join(Modes.reader_thread,NULL); // Wait on reader thread exit
|
||||||
|
|
||||||
// Nothing is touching the rtlsdr device now.
|
|
||||||
|
|
||||||
if (Modes.filename == NULL) {
|
|
||||||
// This currently causes crashes within libusb for unknown reasons:
|
|
||||||
//rtlsdr_close(Modes.dev);
|
|
||||||
}
|
|
||||||
|
|
||||||
pthread_cond_destroy(&Modes.data_cond); // Thread cleanup - only after the reader thread is dead!
|
pthread_cond_destroy(&Modes.data_cond); // Thread cleanup - only after the reader thread is dead!
|
||||||
pthread_mutex_destroy(&Modes.data_mutex);
|
pthread_mutex_destroy(&Modes.data_mutex);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue