diff options
author | Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> | 2024-08-28 13:22:56 +0100 |
---|---|---|
committer | Philippe Mathieu-Daudé <philmd@linaro.org> | 2024-09-13 20:11:13 +0200 |
commit | 28fbf33b3f6925dff8fcf1bae217d850d604a1d3 (patch) | |
tree | 8b71ddf5d6d18f7f051ffdfe703e8ab1b084c0f5 | |
parent | cfc65db19bc9f796f338dc7220811471b6ab2f28 (diff) | |
download | qemu-28fbf33b3f6925dff8fcf1bae217d850d604a1d3.zip qemu-28fbf33b3f6925dff8fcf1bae217d850d604a1d3.tar.gz qemu-28fbf33b3f6925dff8fcf1bae217d850d604a1d3.tar.bz2 |
fifo8: add fifo8_peek_buf() function
This is a wrapper function around fifo8_peekpop_buf() that allows the
caller to peek into the FIFO, including handling the case where there
is a wraparound of the internal FIFO buffer.
Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Reviewed-by: Octavian Purdila <tavip@google.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-ID: <20240828122258.928947-8-mark.cave-ayland@ilande.co.uk>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
-rw-r--r-- | include/qemu/fifo8.h | 14 | ||||
-rw-r--r-- | util/fifo8.c | 5 |
2 files changed, 19 insertions, 0 deletions
diff --git a/include/qemu/fifo8.h b/include/qemu/fifo8.h index d1d0675..d09984b 100644 --- a/include/qemu/fifo8.h +++ b/include/qemu/fifo8.h @@ -77,6 +77,20 @@ uint8_t fifo8_pop(Fifo8 *fifo); uint32_t fifo8_pop_buf(Fifo8 *fifo, uint8_t *dest, uint32_t destlen); /** + * fifo8_peek_buf: + * @fifo: FIFO to read from + * @dest: the buffer to write the data into (can be NULL) + * @destlen: size of @dest and maximum number of bytes to peek + * + * Peek a number of elements from the FIFO up to a maximum of @destlen. + * The peeked data is copied into the @dest buffer. + * Care is taken when the data wraps around in the ring buffer. + * + * Returns: number of bytes peeked. + */ +uint32_t fifo8_peek_buf(Fifo8 *fifo, uint8_t *dest, uint32_t destlen); + +/** * fifo8_pop_bufptr: * @fifo: FIFO to pop from * @max: maximum number of bytes to pop diff --git a/util/fifo8.c b/util/fifo8.c index 1031ffb..a8f5cea 100644 --- a/util/fifo8.c +++ b/util/fifo8.c @@ -140,6 +140,11 @@ uint32_t fifo8_pop_buf(Fifo8 *fifo, uint8_t *dest, uint32_t destlen) return fifo8_peekpop_buf(fifo, dest, destlen, true); } +uint32_t fifo8_peek_buf(Fifo8 *fifo, uint8_t *dest, uint32_t destlen) +{ + return fifo8_peekpop_buf(fifo, dest, destlen, false); +} + void fifo8_drop(Fifo8 *fifo, uint32_t len) { len -= fifo8_pop_buf(fifo, NULL, len); |