@@ -28,6 +28,7 @@ static uint16_t rx_st40p_next_idx(struct st40p_rx_ctx* ctx, uint16_t idx) {
2828static void rx_st40p_block_wake (struct st40p_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}
@@ -330,11 +331,21 @@ static int rx_st40p_stat(void* priv) {
330331
331332 if (!ctx -> ready ) return - EBUSY ; /* not ready */
332333
333- uint16_t producer_idx = ctx -> framebuff_producer_idx ;
334- uint16_t consumer_idx = ctx -> framebuff_consumer_idx ;
334+ uint16_t producer_idx ;
335+ uint16_t consumer_idx ;
336+ enum st40p_rx_frame_status producer_stat ;
337+ enum st40p_rx_frame_status consumer_stat ;
338+
339+ mt_pthread_mutex_lock (& ctx -> lock );
340+ producer_idx = ctx -> framebuff_producer_idx ;
341+ consumer_idx = ctx -> framebuff_consumer_idx ;
342+ producer_stat = framebuff [producer_idx ].stat ;
343+ consumer_stat = framebuff [consumer_idx ].stat ;
344+ mt_pthread_mutex_unlock (& ctx -> lock );
345+
335346 notice ("RX_st40p(%d,%s), p(%d:%s) c(%d:%s)\n" , ctx -> idx , ctx -> ops_name , producer_idx ,
336- rx_st40p_stat_name (framebuff [ producer_idx ]. stat ), consumer_idx ,
337- rx_st40p_stat_name (framebuff [ consumer_idx ]. stat ));
347+ rx_st40p_stat_name (producer_stat ), consumer_idx ,
348+ rx_st40p_stat_name (consumer_stat ));
338349
339350 notice ("RX_st40p(%d), frame get try %d succ %d, put %d\n" , ctx -> idx ,
340351 ctx -> stat_get_frame_try , ctx -> stat_get_frame_succ , ctx -> stat_put_frame );
@@ -355,8 +366,12 @@ static int rx_st40p_get_block_wait(struct st40p_rx_ctx* ctx) {
355366 dbg ("%s(%d), start\n" , __func__ , ctx -> idx );
356367 /* wait on the block cond */
357368 mt_pthread_mutex_lock (& ctx -> block_wake_mutex );
358- mt_pthread_cond_timedwait_ns (& ctx -> block_wake_cond , & ctx -> block_wake_mutex ,
359- ctx -> block_timeout_ns );
369+ while (!ctx -> block_wake_pending ) {
370+ int ret = mt_pthread_cond_timedwait_ns (& ctx -> block_wake_cond , & ctx -> block_wake_mutex ,
371+ ctx -> block_timeout_ns );
372+ if (ret ) break ;
373+ }
374+ ctx -> block_wake_pending = false;
360375 mt_pthread_mutex_unlock (& ctx -> block_wake_mutex );
361376 dbg ("%s(%d), end\n" , __func__ , ctx -> idx );
362377 return 0 ;
@@ -557,6 +572,7 @@ st40p_rx_handle st40p_rx_create(mtl_handle mt, struct st40p_rx_ops* ops) {
557572 mt_pthread_mutex_init (& ctx -> block_wake_mutex , NULL );
558573 mt_pthread_cond_wait_init (& ctx -> block_wake_cond );
559574 ctx -> block_timeout_ns = NS_PER_S ;
575+ ctx -> block_wake_pending = false;
560576 if (ops -> flags & ST40P_RX_FLAG_BLOCK_GET ) ctx -> block_get = true;
561577
562578 /* copy ops */
0 commit comments