Skip to content

Commit ba0b5e4

Browse files
committed
Fix: add block wake pending flag to ST20 and ST30 RX contexts for improved synch
1 parent f1934c8 commit ba0b5e4

File tree

4 files changed

+44
-12
lines changed

4 files changed

+44
-12
lines changed

lib/src/st2110/pipeline/st20_pipeline_rx.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ static uint16_t rx_st20p_next_idx(struct st20p_rx_ctx* ctx, uint16_t idx) {
2828
static 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
757758
static 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 */

lib/src/st2110/pipeline/st20_pipeline_rx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ struct st20p_rx_ctx {
5252
pthread_cond_t block_wake_cond;
5353
pthread_mutex_t block_wake_mutex;
5454
uint64_t block_timeout_ns;
55+
bool block_wake_pending;
5556

5657
struct st20_convert_session_impl* convert_impl;
5758
struct st_frame_converter* internal_converter;

lib/src/st2110/pipeline/st30_pipeline_rx.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ static uint16_t rx_st30p_next_idx(struct st30p_rx_ctx* ctx, uint16_t idx) {
2828
static void rx_st30p_block_wake(struct st30p_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
}
@@ -194,14 +195,23 @@ static int rx_st30p_init_fbs(struct st30p_rx_ctx* ctx, struct st30p_rx_ops* ops)
194195
static int rx_st30p_stat(void* priv) {
195196
struct st30p_rx_ctx* ctx = priv;
196197
struct st30p_rx_frame* framebuff = ctx->framebuffs;
198+
uint16_t producer_idx;
199+
uint16_t consumer_idx;
200+
enum st30p_rx_frame_status producer_stat;
201+
enum st30p_rx_frame_status consumer_stat;
197202

198203
if (!ctx->ready) return -EBUSY; /* not ready */
199204

200-
uint16_t producer_idx = ctx->framebuff_producer_idx;
201-
uint16_t consumer_idx = ctx->framebuff_consumer_idx;
205+
mt_pthread_mutex_lock(&ctx->lock);
206+
producer_idx = ctx->framebuff_producer_idx;
207+
consumer_idx = ctx->framebuff_consumer_idx;
208+
producer_stat = framebuff[producer_idx].stat;
209+
consumer_stat = framebuff[consumer_idx].stat;
210+
mt_pthread_mutex_unlock(&ctx->lock);
211+
202212
notice("RX_st30p(%d,%s), p(%d:%s) c(%d:%s)\n", ctx->idx, ctx->ops_name, producer_idx,
203-
rx_st30p_stat_name(framebuff[producer_idx].stat), consumer_idx,
204-
rx_st30p_stat_name(framebuff[consumer_idx].stat));
213+
rx_st30p_stat_name(producer_stat), consumer_idx,
214+
rx_st30p_stat_name(consumer_stat));
205215

206216
notice("RX_st30p(%d), frame get try %d succ %d, put %d\n", ctx->idx,
207217
ctx->stat_get_frame_try, ctx->stat_get_frame_succ, ctx->stat_put_frame);
@@ -221,8 +231,12 @@ static int rx_st30p_get_block_wait(struct st30p_rx_ctx* ctx) {
221231
dbg("%s(%d), start\n", __func__, ctx->idx);
222232
/* wait on the block cond */
223233
mt_pthread_mutex_lock(&ctx->block_wake_mutex);
224-
mt_pthread_cond_timedwait_ns(&ctx->block_wake_cond, &ctx->block_wake_mutex,
225-
ctx->block_timeout_ns);
234+
while (!ctx->block_wake_pending) {
235+
int ret = mt_pthread_cond_timedwait_ns(&ctx->block_wake_cond, &ctx->block_wake_mutex,
236+
ctx->block_timeout_ns);
237+
if (ret) break;
238+
}
239+
ctx->block_wake_pending = false;
226240
mt_pthread_mutex_unlock(&ctx->block_wake_mutex);
227241
dbg("%s(%d), end\n", __func__, ctx->idx);
228242
return 0;
@@ -437,6 +451,7 @@ st30p_rx_handle st30p_rx_create(mtl_handle mt, struct st30p_rx_ops* ops) {
437451
mt_pthread_mutex_init(&ctx->block_wake_mutex, NULL);
438452
mt_pthread_cond_wait_init(&ctx->block_wake_cond);
439453
ctx->block_timeout_ns = NS_PER_S;
454+
ctx->block_wake_pending = false;
440455
if (ops->flags & ST30P_RX_FLAG_BLOCK_GET) ctx->block_get = true;
441456

442457
/* copy ops */

lib/src/st2110/pipeline/st30_pipeline_rx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ struct st30p_rx_ctx {
4949
pthread_cond_t block_wake_cond;
5050
pthread_mutex_t block_wake_mutex;
5151
uint64_t block_timeout_ns;
52+
bool block_wake_pending;
5253

5354
/* get frame stat */
5455
int stat_get_frame_try;

0 commit comments

Comments
 (0)