threadshare: Fix shutdown race condition

We might've already handled the shutdown unparking while doing the
previous turn(s), so we have to check the atomic bool afterwards again
and before waiting (potentially) forever.

Fixes https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/issues/75
This commit is contained in:
Sebastian Dröge 2019-10-02 12:00:03 +03:00
parent 429e3027b3
commit b84388b0f3

View file

@ -113,6 +113,7 @@ impl IOContextRunner {
::tokio_timer::with_default(&timer_handle, &mut enter, |mut enter| {
::tokio_reactor::with_default(&handle, &mut enter, |enter| loop {
if self.shutdown.load(atomic::Ordering::SeqCst) > RUNNING {
gst_debug!(CONTEXT_CAT, "Shutting down loop");
break;
}
@ -167,6 +168,13 @@ impl IOContextRunner {
{}
gst_trace!(CONTEXT_CAT, "Turned current thread '{}'", self.name);
// We have to check again after turning in case we're supposed to shut down now
// and already handled the unpark above
if self.shutdown.load(atomic::Ordering::SeqCst) > RUNNING {
gst_debug!(CONTEXT_CAT, "Shutting down loop");
break;
}
let elapsed = now.elapsed();
gst_trace!(CONTEXT_CAT, "Elapsed {:?} after handling futures", elapsed);