From e65e79bb81fcc87e5bb6c1ef83b39d480c785764 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 12 Dec 2025 12:43:12 +0700 Subject: [PATCH] add back tu_fifo_discard_n() since it may be useful in the future. --- src/common/tusb_fifo.c | 9 +++++++++ src/common/tusb_fifo.h | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/src/common/tusb_fifo.c b/src/common/tusb_fifo.c index 2faf72ba8..e97b6ccce 100644 --- a/src/common/tusb_fifo.c +++ b/src/common/tusb_fifo.c @@ -448,6 +448,15 @@ uint16_t tu_fifo_write_n_access_mode(tu_fifo_t *f, const void *data, uint16_t n, return n; } +uint16_t tu_fifo_discard_n(tu_fifo_t *f, uint16_t n) { + const uint16_t count = tu_min16(n, tu_fifo_count(f)); // limit to available count + ff_lock(f->mutex_rd); + f->rd_idx = advance_index(f->depth, f->rd_idx, count); + ff_unlock(f->mutex_rd); + + return count; +} + //--------------------------------------------------------------------+ // One API //--------------------------------------------------------------------+ diff --git a/src/common/tusb_fifo.h b/src/common/tusb_fifo.h index f13c195e5..2e2a0db6f 100644 --- a/src/common/tusb_fifo.h +++ b/src/common/tusb_fifo.h @@ -205,6 +205,10 @@ TU_ATTR_ALWAYS_INLINE static inline uint16_t tu_fifo_read_n(tu_fifo_t *f, void * return tu_fifo_read_n_access_mode(f, buffer, n, TU_FIFO_INC_ADDR_RW8); } +// discard first n items from fifo i.e advance read pointer by n with mutex +// return number of discarded items +uint16_t tu_fifo_discard_n(tu_fifo_t *f, uint16_t n); + //--------------------------------------------------------------------+ // Write API //--------------------------------------------------------------------+