@@ -44,8 +44,9 @@ static void rx_st20p_notify_frame_available(struct st20p_rx_ctx* ctx) {
4444 }
4545}
4646
47+ /* Caller must hold ctx->lock before invoking to keep framebuff->stat coherent. */
4748static struct st20p_rx_frame * rx_st20p_next_available (
48- struct st20p_rx_ctx * ctx , uint16_t idx_start , enum st20p_rx_frame_status desired ) {
49+ struct st20p_rx_ctx * ctx , uint16_t idx_start , enum st20p_rx_frame_status desired ) {
4950 uint16_t idx = idx_start ;
5051 struct st20p_rx_frame * framebuff ;
5152
@@ -422,9 +423,11 @@ static int rx_st20p_convert_put_frame(void* priv, struct st20_convert_frame_meta
422423 return - EIO ;
423424 }
424425
426+ mt_pthread_mutex_lock (& ctx -> lock );
425427 if (ST20P_RX_FRAME_IN_CONVERTING != framebuff -> stat ) {
426428 err ("%s(%d), frame %u not in converting %d\n" , __func__ , idx , convert_idx ,
427429 framebuff -> stat );
430+ mt_pthread_mutex_unlock (& ctx -> lock );
428431 return - EIO ;
429432 }
430433
@@ -438,10 +441,12 @@ static int rx_st20p_convert_put_frame(void* priv, struct st20_convert_frame_meta
438441 framebuff -> stat = ST20P_RX_FRAME_CONVERTED ;
439442 rx_st20p_notify_frame_available (ctx );
440443 }
444+ mt_pthread_mutex_unlock (& ctx -> lock );
441445
442446 return 0 ;
443447}
444448
449+ /* Locking skipped—minor inconsistencies are acceptable here */
445450static int rx_st20p_convert_dump (void * priv ) {
446451 struct st20p_rx_ctx * ctx = priv ;
447452 struct st20p_rx_frame * framebuff = ctx -> framebuffs ;
@@ -926,16 +931,19 @@ int st20p_rx_put_frame(st20p_rx_handle handle, struct st_frame* frame) {
926931 return - EIO ;
927932 }
928933
934+ mt_pthread_mutex_lock (& ctx -> lock );
929935 if (ST20P_RX_FRAME_IN_USER != framebuff -> stat ) {
930936 err ("%s(%d), frame %u not in user %d\n" , __func__ , idx , consumer_idx ,
931937 framebuff -> stat );
938+ mt_pthread_mutex_unlock (& ctx -> lock );
932939 return - EIO ;
933940 }
934941
935942 /* free the frame */
936943 st20_rx_put_framebuff (ctx -> transport , framebuff -> src .addr [0 ]);
937944 framebuff -> stat = ST20P_RX_FRAME_FREE ;
938945 ctx -> stat_put_frame ++ ;
946+ mt_pthread_mutex_unlock (& ctx -> lock );
939947
940948 MT_USDT_ST20P_RX_FRAME_PUT (idx , framebuff -> idx , frame -> addr [0 ]);
941949 dbg ("%s(%d), frame %u succ\n" , __func__ , idx , consumer_idx );
0 commit comments