laforge has submitted this change. ( https://gerrit.osmocom.org/c/osmo-e1d/+/27848 )
Change subject: octoi: Fix frame_rifo_depth() function ......................................................................
octoi: Fix frame_rifo_depth() function
We use the 'correct' math in frame_rifo_depth now so the count is accurate down to zero.
We need to fixup the logic that drags the 'write pointer' (last_in_fn) along when reading from an empty FIFO.
We also need proper init (which was missing alltogether beforehand).
Change-Id: I088f181e74358eb2c96a7aab7a7c875b9276d980 Signed-off-by: Sylvain Munaut tnt@246tNt.com --- M src/octoi/frame_rifo.c M src/octoi/frame_rifo.h 2 files changed, 6 insertions(+), 4 deletions(-)
Approvals: Jenkins Builder: Verified laforge: Looks good to me, approved
diff --git a/src/octoi/frame_rifo.c b/src/octoi/frame_rifo.c index 94758e9..876f023 100644 --- a/src/octoi/frame_rifo.c +++ b/src/octoi/frame_rifo.c @@ -97,6 +97,7 @@ memset(rifo->buf, 0xff, sizeof(rifo->buf)); rifo->next_out = rifo->buf; rifo->next_out_fn = 0; + rifo->last_in_fn = -1; memset(rifo->bitvec, 0, sizeof(rifo->bitvec)); }
@@ -151,10 +152,11 @@ if (rifo->next_out >= RIFO_BUF_END(rifo)) rifo->next_out -= sizeof(rifo->buf);
+ /* if we're empty we 'drag' last_in along to avoid overflows */ + if (frame_rifo_depth(rifo) == 0) + rifo->last_in_fn += 1; + rifo->next_out_fn += 1; - /* make sure that frame_rifo_depth() doing last_in - next_out won't overflow */ - if (rifo->next_out_fn == rifo->last_in_fn + 1) - rifo->last_in_fn = rifo->next_out_fn;
return rc; } diff --git a/src/octoi/frame_rifo.h b/src/octoi/frame_rifo.h index 401e873..ac97506 100644 --- a/src/octoi/frame_rifo.h +++ b/src/octoi/frame_rifo.h @@ -24,7 +24,7 @@ /* current depth of RIFO */ static inline unsigned int frame_rifo_depth(struct frame_rifo *rifo) { - return rifo->last_in_fn - rifo->next_out_fn; + return rifo->last_in_fn - rifo->next_out_fn + 1; }
void frame_rifo_init(struct frame_rifo *rifo);