Skip to content

Commit a804a1a

Browse files
committed
simplify and remove _tu_fifo_empty, _tu_fifo_full. Also correct full condition check
1 parent 2d78492 commit a804a1a

File tree

1 file changed

+7
-23
lines changed

1 file changed

+7
-23
lines changed

src/common/tusb_fifo.c

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@
3838

3939
#if OSAL_MUTEX_REQUIRED
4040

41-
static inline void _ff_lock(osal_mutex_t mutex)
41+
TU_ATTR_ALWAYS_INLINE static inline void _ff_lock(osal_mutex_t mutex)
4242
{
4343
if (mutex) osal_mutex_lock(mutex, OSAL_TIMEOUT_WAIT_FOREVER);
4444
}
4545

46-
static inline void _ff_unlock(osal_mutex_t mutex)
46+
TU_ATTR_ALWAYS_INLINE static inline void _ff_unlock(osal_mutex_t mutex)
4747
{
4848
if (mutex) osal_mutex_unlock(mutex);
4949
}
@@ -361,30 +361,14 @@ static inline uint16_t idx2ptr(uint16_t idx, uint16_t depth)
361361
// Works on local copies of w and r - return only the difference and as such can be used to determine an overflow
362362
static inline uint16_t _tu_fifo_count(tu_fifo_t* f, uint16_t wr_idx, uint16_t rd_idx)
363363
{
364-
uint16_t cnt;
365-
366364
// In case we have non-power of two depth we need a further modification
367365
if (wr_idx >= rd_idx)
368366
{
369-
cnt = (uint16_t) (wr_idx - rd_idx);
367+
return (uint16_t) (wr_idx - rd_idx);
370368
} else
371369
{
372-
cnt = (uint16_t) (2*f->depth - (rd_idx - wr_idx));
370+
return (uint16_t) (2*f->depth - (rd_idx - wr_idx));
373371
}
374-
375-
return cnt;
376-
}
377-
378-
// Works on local copies of w and r
379-
static inline bool _tu_fifo_empty(uint16_t wr_idx, uint16_t rd_idx)
380-
{
381-
return wr_idx == rd_idx;
382-
}
383-
384-
// Works on local copies of w and r
385-
static inline bool _tu_fifo_full(tu_fifo_t* f, uint16_t wAbs, uint16_t rAbs)
386-
{
387-
return _tu_fifo_count(f, wAbs, rAbs) == f->depth;
388372
}
389373

390374
// Works on local copies of w and r
@@ -601,7 +585,7 @@ uint16_t tu_fifo_count(tu_fifo_t* f)
601585
/******************************************************************************/
602586
bool tu_fifo_empty(tu_fifo_t* f)
603587
{
604-
return _tu_fifo_empty(f->wr_idx, f->rd_idx);
588+
return f->wr_idx == f->rd_idx;
605589
}
606590

607591
/******************************************************************************/
@@ -619,7 +603,7 @@ bool tu_fifo_empty(tu_fifo_t* f)
619603
/******************************************************************************/
620604
bool tu_fifo_full(tu_fifo_t* f)
621605
{
622-
return _tu_fifo_full(f, f->wr_idx, f->rd_idx);
606+
return _tu_fifo_count(f, f->wr_idx, f->rd_idx) >= f->depth;
623607
}
624608

625609
/******************************************************************************/
@@ -798,7 +782,7 @@ bool tu_fifo_write(tu_fifo_t* f, const void * data)
798782
bool ret;
799783
uint16_t const wr_idx = f->wr_idx;
800784

801-
if ( _tu_fifo_full(f, wr_idx, f->rd_idx) && !f->overwritable )
785+
if ( tu_fifo_full(f) && !f->overwritable )
802786
{
803787
ret = false;
804788
}else

0 commit comments

Comments
 (0)