@@ -28,6 +28,7 @@ static uint16_t rx_st20p_next_idx(struct st20p_rx_ctx* ctx, uint16_t idx) {
2828static void rx_st20p_block_wake (struct st20p_rx_ctx * ctx ) {
2929 /* notify block */
3030 mt_pthread_mutex_lock (& ctx -> block_wake_mutex );
31+ ctx -> block_wake_pending = true;
3132 mt_pthread_cond_signal (& ctx -> block_wake_cond );
3233 mt_pthread_mutex_unlock (& ctx -> block_wake_mutex );
3334}
@@ -757,14 +758,23 @@ static int rx_st20p_get_converter(struct mtl_main_impl* impl, struct st20p_rx_ct
757758static int rx_st20p_stat (void * priv ) {
758759 struct st20p_rx_ctx * ctx = priv ;
759760 struct st20p_rx_frame * framebuff = ctx -> framebuffs ;
761+ uint16_t producer_idx ;
762+ uint16_t consumer_idx ;
763+ enum st20p_rx_frame_status producer_stat ;
764+ enum st20p_rx_frame_status consumer_stat ;
760765
761766 if (!ctx -> ready ) return - EBUSY ; /* not ready */
762767
763- uint16_t producer_idx = ctx -> framebuff_producer_idx ;
764- uint16_t consumer_idx = ctx -> framebuff_consumer_idx ;
768+ mt_pthread_mutex_lock (& ctx -> lock );
769+ producer_idx = ctx -> framebuff_producer_idx ;
770+ consumer_idx = ctx -> framebuff_consumer_idx ;
771+ producer_stat = framebuff [producer_idx ].stat ;
772+ consumer_stat = framebuff [consumer_idx ].stat ;
773+ mt_pthread_mutex_unlock (& ctx -> lock );
774+
765775 notice ("RX_st20p(%d,%s), p(%d:%s) c(%d:%s)\n" , ctx -> idx , ctx -> ops_name , producer_idx ,
766- rx_st20p_stat_name (framebuff [ producer_idx ]. stat ), consumer_idx ,
767- rx_st20p_stat_name (framebuff [ consumer_idx ]. stat ));
776+ rx_st20p_stat_name (producer_stat ), consumer_idx ,
777+ rx_st20p_stat_name (consumer_stat ));
768778
769779 notice ("RX_st20p(%d), frame get try %d succ %d, put %d\n" , ctx -> idx ,
770780 ctx -> stat_get_frame_try , ctx -> stat_get_frame_succ , ctx -> stat_put_frame );
@@ -810,8 +820,12 @@ static int st20p_rx_get_block_wait(struct st20p_rx_ctx* ctx) {
810820 dbg ("%s(%d), start\n" , __func__ , ctx -> idx );
811821 /* wait on the block cond */
812822 mt_pthread_mutex_lock (& ctx -> block_wake_mutex );
813- mt_pthread_cond_timedwait_ns (& ctx -> block_wake_cond , & ctx -> block_wake_mutex ,
814- ctx -> block_timeout_ns );
823+ while (!ctx -> block_wake_pending ) {
824+ int ret = mt_pthread_cond_timedwait_ns (& ctx -> block_wake_cond , & ctx -> block_wake_mutex ,
825+ ctx -> block_timeout_ns );
826+ if (ret ) break ;
827+ }
828+ ctx -> block_wake_pending = false;
815829 mt_pthread_mutex_unlock (& ctx -> block_wake_mutex );
816830 dbg ("%s(%d), end\n" , __func__ , ctx -> idx );
817831 return 0 ;
@@ -997,6 +1011,7 @@ st20p_rx_handle st20p_rx_create(mtl_handle mt, struct st20p_rx_ops* ops) {
9971011 mt_pthread_mutex_init (& ctx -> block_wake_mutex , NULL );
9981012 mt_pthread_cond_wait_init (& ctx -> block_wake_cond );
9991013 ctx -> block_timeout_ns = NS_PER_S ;
1014+ ctx -> block_wake_pending = false;
10001015 if (ops -> flags & ST20P_RX_FLAG_BLOCK_GET ) ctx -> block_get = true;
10011016
10021017 /* copy ops */
0 commit comments