add back tu_fifo_discard_n() since it may be useful in the future.

This commit is contained in:
hathach
2025-12-12 12:43:12 +07:00
parent d71e3c9ea6
commit e65e79bb81
2 changed files with 13 additions and 0 deletions

View File

@ -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
//--------------------------------------------------------------------+

View File

@ -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
//--------------------------------------------------------------------+