Commit Graph

11 Commits

Author SHA1 Message Date
Oliver Jowett 8dd83d2e7e Don't hang on exit if rtlsdr hardware stops sending samples.
Give up and exit after 30 seconds of no sample data, rather than just warning and continuing.

background & discussion: https://discussions.flightaware.com/t/cpu-hikes-crash-dump1090-fa/74759

The scenario this addresses is:

 * Hardware wedges, USB bulk endpoint stops providing data
 * librtlsdr remains in rtlsdr_read_async() waiting for either USB data which never arrives,
   or a cancellation via _a different thread_ calling rtlsdr_cancel_async().
 * main thread notices the lack of SDR data and complains
 * something external e.g. piaware tries a restart and sends SIGTERM
 * the signal handler sets Modes.exit = 1; the main thread starts waiting for receive thread termination
 * because we're never getting callbacks from rtlsdr_read_async(), we never call rtlsdr_cancel_async
 * dump1090 hangs waiting on receive thread termination

To fix this, add a sdrStop() handler function where the general contract is "make the receive thread terminate".
In the rtlsdr case, this calls rtlsdr_cancel_async directly, which will make rtlsdr_read_async() return even
if the hardware is stuck.

The main thread then calls sdrStop() before waiting for receive thread termination.

Also, as discussed in the thread above, there's not really much point in continuing to run if the SDR
has wedged, so bail out after 30 seconds of no sample data.

Also, if pthread_timedjoin_np is available, use it in preference to pthread_join so that we do not wait
indefinitely for the receive thread on shutdown. If the join times out, give up and abort() as we can't
safely continue a clean shutdown while the receive thread is running.
2021-03-21 02:03:08 +08:00
Gluttton 992f036fc2 fix a trivial copy-paste typo in comments
Signed-off-by: Gluttton <gluttton@ukr.net>
2020-08-31 22:53:14 +03:00
Oliver Jowett 74607b31ed Factor out FIFO handling; reimplement as a linked list, not a circular buffer.
Update all the SDR implementation to use it.

This was getting pretty ugly with code getting copy&pasted in all the SDR
implementations. Unify it all and give it a simpler API. Linked list works out
much simpler than the circular buffer. Also, simplify copying the overlap region
around by just using a separate buffer (it's only a few hundred bytes long, so
the double copy is not a big deal).
2020-08-05 19:50:38 +08:00
Oliver Jowett 8b21104d66 Factor out sdr thread CPU monitoring 2020-08-05 19:50:38 +08:00
Oliver Jowett f82b7b7a8c Set SDR thread name if pthread_setname_np() is available 2020-08-05 19:50:38 +08:00
Oliver Jowett 6986b3847f WIP on new faup1090 output, data aging, refactoring 2017-12-02 17:38:33 +00:00
Oliver Jowett 2142d2edf5 Whitespace changes only: cleaning up trailing whitespace at EOL 2017-06-15 18:17:07 +01:00
Oliver Jowett bfc4b742af Move {start,end}_cpu_timing into util.c 2017-01-27 12:33:43 +00:00
Oliver Jowett c0af448efa uint64_t (even at 12MHz) isn't going to overflow any time soon, don't worry about wrapping. 2015-02-08 17:59:20 +00:00
Oliver Jowett 4e177c2d64 Store computed reception time in the message struct so we don't rely on
the message being emitted immediately.

Fix computation of reception time so it's more sensible (the block timestamp
is some time after reception of the _end_ of the block, not the start) - this
means that message-emission times are always later than message-reception
times in SBS output, which is a bit more sensible.

Use clock_gettime in preference to ftime.
2015-02-08 17:46:01 +00:00
Oliver Jowett 899c51ce85 Only emit network messages once we have seen two of them
(except in --net-verbatim mode, where we emit them all)

Move aircraft tracking into track.[ch].

Clean up references to "interactive mode" when tracking
aircraft - we always track aircraft, even in non-interactive
mode.
2015-02-08 14:27:03 +00:00