This is something I've had lying around for a little while as a follow on from
Phil's recent work on Fifo8 with a few updates, but also adding the missing
fifo8_peek() and fifo8_peek_buf() functions along with some relevant tests.
The reason for sending this now is that there are couple of recent series
(https://patchew.org/QEMU/20240819113148.3007047-1-alistair.francis@wdc.com/ and
https://patchew.org/QEMU/20240817102606.3996242-1-tavip@google.com/) which can
benefit from these changes: in particular the fifo8_peek_buf() function, unlike the
existing fifo8_peek_bufptr() function, will correctly handle FIFO wraparound. This
occurs when the FIFO head drifts due to not popping the entire FIFO content in one
go, which often happens when trying to send FIFO data to a chardev.
Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Mark Cave-Ayland (9):
fifo8: rename fifo8_peekpop_buf() to fifo8_peekpop_bufptr()
fifo8: introduce head variable for fifo8_peekpop_bufptr()
fifo8: add skip parameter to fifo8_peekpop_bufptr()
fifo8: replace fifo8_pop_bufptr() with fifo8_peekpop_bufptr() in
fifo8_pop_buf()
fifo8: rename fifo8_pop_buf() to fifo8_peekpop_buf()
fifo8: honour do_pop argument in fifo8_peekpop_buf()
fifo8: add fifo8_peek_buf() function
fifo8: introduce fifo8_peek() function
tests/unit: add test-fifo unit test
include/qemu/fifo8.h | 25 ++++
tests/unit/meson.build | 1 +
tests/unit/test-fifo.c | 256 +++++++++++++++++++++++++++++++++++++++++
util/fifo8.c | 42 +++++--
4 files changed, 313 insertions(+), 11 deletions(-)
create mode 100644 tests/unit/test-fifo.c
--
2.39.2