From 1962092d9675f76604414086200e88f6c857346f Mon Sep 17 00:00:00 2001 From: Sylvain BERTRAND Date: Tue, 15 Sep 2020 00:51:12 +0000 Subject: [PATCH] npv: tidy mutex locking --- npv/audio/filt/public/code.frag.c | 2 +- npv/local/code.frag.c | 22 +++---- npv/lock_hierarchy | 118 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+), 15 deletions(-) create mode 100644 npv/lock_hierarchy diff --git a/npv/audio/filt/public/code.frag.c b/npv/audio/filt/public/code.frag.c index 9fb7eae..57ff928 100644 --- a/npv/audio/filt/public/code.frag.c +++ b/npv/audio/filt/public/code.frag.c @@ -9,7 +9,7 @@ STATIC u8 filt_push_dec_sets(void) avutil_audio_set_ref_t **a; npv_audio_dec_sets_lock(); - if (npv_audio_dec_sets_p.n == 0) { + if (npv_audio_dec_sets_p.n == 0) { if (npv_audio_dec_sets_p.eof_receive) { ri = avfilter_bufsrc_add_audio_set_flags(abufsrc_ctx_l, 0, AVFILTER_BUFSRC_FLAG_PUSH diff --git a/npv/local/code.frag.c b/npv/local/code.frag.c index 70847d5..e9e3f8c 100644 --- a/npv/local/code.frag.c +++ b/npv/local/code.frag.c @@ -505,33 +505,27 @@ STATIC void npv_cmd_quit(void) } STATIC void seek_lock(void) { - /* fmt */ - npv_fmt_ctx_lock(); - /* video */ + /* see lock_hierarchy file */ npv_pkt_q_lock(npv_video_pkt_q_p); - npv_video_dec_frs_lock(); npv_video_dec_ctx_lock(); - /* audio (useless from the main thd though) */ + npv_video_dec_frs_lock(); npv_pkt_q_lock(npv_audio_pkt_q_p); - npv_audio_dec_sets_lock(); npv_audio_dec_ctx_lock(); - + npv_audio_dec_sets_lock(); npv_pipeline_limits_lock(); + npv_fmt_ctx_lock(); } STATIC void seek_unlock(void) { + /* see lock_hierarchy file */ + npv_fmt_ctx_unlock(); npv_pipeline_limits_unlock(); - - /* audio */ - npv_audio_dec_ctx_unlock(); npv_audio_dec_sets_unlock(); + npv_audio_dec_ctx_unlock(); npv_pkt_q_unlock(npv_audio_pkt_q_p); - /* video */ - npv_video_dec_ctx_unlock(); npv_video_dec_frs_unlock(); + npv_video_dec_ctx_unlock(); npv_pkt_q_unlock(npv_video_pkt_q_p); - /* fmt */ - npv_fmt_ctx_unlock(); } #define TS_FROM_CLK_OK 0 STATIC void seek_x(s64 delta) diff --git a/npv/lock_hierarchy b/npv/lock_hierarchy new file mode 100644 index 0000000..5236908 --- /dev/null +++ b/npv/lock_hierarchy @@ -0,0 +1,118 @@ +When several mutexes happen to be locked at the same time in any thread, they +must be locked in the same order in all threads. This is the dangerous nested +locking. Nested locking is accounted for using uppercase letters. +-------- +MAIN_THD +-------- +main + npv_prefill_wait + npv_pipeline_limits_lock + npv_pipeline_limits_unlock + evts_loop + |npv_xcb_evt + | npv_xcb_evt_handle + | npv_xcb_evt_key_release + | |(npv_cmd_rewind | npv_cmd_rewind_big | npv_cmd_fastforward | npv_cmd_fastforward_big) + | | seek_x + | | |seek_lock + | | | A npv_pkt_q_lock(npv_video_pkt_q_p) + | | | B npv_video_dec_ctx_lock + | | | C npv_video_dec_frs_lock + | | | D npv_pkt_q_lock(npv_audio_pkt_q_p) + | | | E npv_audio_dec_ctx_lock + | | | F npv_audio_dec_sets_lock + | | | G npv_pipeline_limits_lock + | | | H npv_fmt_ctx_lock + | | |seek_unlock + | | | npv_pkt_q_unlock(npv_video_pkt_q_p) + | | | npv_video_dec_ctx_unlock + | | | npv_video_dec_frs_unlock + | | | npv_pkt_q_unlock(npv_audio_pkt_q_p) + | | | npv_audio_dec_ctx_unlock + | | | npv_audio_dec_sets_unlock + | | | npv_pipeline_limits_unlock + | | | npv_fmt_ctx_unlock + | | |npv_prefill_wait + | | npv_pipeline_limits_lock + | | npv_pipeline_limits_unlock + | |npv_cmd_pause + | npv_fmt_ctx_lock + | npv_fmt_ctx_unlock + |npv_audio_evt_pcm_write + | npv_audio_pcm_filt_frs_write + | npv_audio_filt_push_decs_sets + | npv_audio_dec_sets_lock + | npv_audio_dec_sets_unlock + |npv_video_timer_evt + npv_video_dec_frs_lock + npv_video_dec_frs_unlock + npv_video_start_scaling + npv_thdsws_run + npv_thdsws_state_lock + npv_thdsws_state_unlock + cond_signal on npv_thdsws_state_(un)lock mutex +--------- +VIDEO_THD +--------- +npv_pipeline_video_thd_entry + npv_pipeline_video + have_enough_predecoded_video_frs + npv_video_dec_frs_lock + npv_video_dec_frs_unlock + npv_video_pkts_send + A npv_pkt_q_lock(npv_video_pkt_q_p) + B npv_video_dec_ctx_lock + npv_video_dec_ctx_unlock + G npv_pipeline_limits_lock + npv_pipeline_limits_unlock + npv_pkt_q_unlock(npv_video_pkt_q_p) + npv_video_dec_frs_receive_avail + npv_video_dec_fr_try_receive + npv_video_dec_ctx_lock + npv_video_dec_ctx_unlock + npv_video_dec_frs_lock + npv_video_dec_frs_unlock +------- +SWS_THD +------- +npv_thdsws_worker_entry + npv_thdsws_state_lock + npv_thdsws_worker + npv_thdsws_state_unlock + npv_thdsws_state_lock + cond_wait on npv_thdsws_state_(un)lock mutex +--------- +AUDIO_THD +--------- +npv_pipeline_audio_thd_entry + npv_pipeline_audio + have_enough_predecoded_audio_frs + npv_audio_dec_sets_lock + npv_audio_dec_sets_unlock + npv_audio_pkts_send + D npv_pkt_q_lock(npv_audio_pkt_q_p) + E npv_audio_dec_ctx_lock + npv_audio_dec_ctx_unlock + G npv_pipeline_limits_lock + npv_pipeline_limits_unlock + npv_pkt_q_unlock(npv_audio_pkt_q_p) + npv_audio_dec_sets_receive_avail + E npv_audio_dec_ctx_lock + F npv_audio_dec_sets_lock + npv_audio_dec_sets_unlock + npv_audio_dec_ctx_unlock +-------- +READ_THD +-------- +npv_pipeline_read_thd_entry + npv_pipeline_read_ + npv_fmt_pkts_read_and_q + npv_fmt_did_reached_limits + npv_pipeline_limits_lock + npv_pipeline_limits_unlock + npv_fmt_ctx_lock + npv_fmt_ctx_unlock + npv_pipeline_limits_lock + npv_pipeline_limits_unlock + npv_pkt_q_lock(npv_audio_pkt_q_p) | npv_pkt_q_lock(npv_video_pkt_q_p) + npv_pkt_q_unlock(npv_audio_pkt_q_p) | npv_pkt_q_unlock(npv_video_pkt_q_p) -- 2.11.4.GIT