togglerecord: Fix lock ordering

Fixes deadlocks.

Correct lock ordering is:
1) Main stream state lock
2) Other stream state lock
3) Recording state lock
This commit is contained in:
Vivia Nikolaidou 2021-09-23 11:58:06 +03:00
parent 3260651671
commit f6aa03b58a

View file

@ -681,6 +681,8 @@ impl ToggleRecord {
// above but all notifying must happen while the main_stream state is locked as per above. // above but all notifying must happen while the main_stream state is locked as per above.
self.main_stream_cond.notify_all(); self.main_stream_cond.notify_all();
state = stream.state.lock();
let mut rec_state = self.state.lock(); let mut rec_state = self.state.lock();
// Wait until the main stream advanced completely past our current running time in // Wait until the main stream advanced completely past our current running time in
@ -709,7 +711,7 @@ impl ToggleRecord {
current_running_time.map_or(false, |cur_rt| last_rec_stop <= cur_rt) current_running_time.map_or(false, |cur_rt| last_rec_stop <= cur_rt)
})) }))
&& !main_state.eos && !main_state.eos
&& !stream.state.lock().flushing && !state.flushing
{ {
gst_log!( gst_log!(
CAT, CAT,
@ -723,12 +725,12 @@ impl ToggleRecord {
); );
drop(rec_state); drop(rec_state);
drop(state);
self.main_stream_cond.wait(&mut main_state); self.main_stream_cond.wait(&mut main_state);
state = stream.state.lock();
rec_state = self.state.lock(); rec_state = self.state.lock();
} }
state = stream.state.lock();
if state.flushing { if state.flushing {
gst_debug!(CAT, obj: pad, "Flushing"); gst_debug!(CAT, obj: pad, "Flushing");
return Ok(HandleResult::Flushing); return Ok(HandleResult::Flushing);