[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 7/9] fifo8: add fifo8_peek_buf() function
|
From: |
Octavian Purdila |
|
Subject: |
Re: [PATCH 7/9] fifo8: add fifo8_peek_buf() function |
|
Date: |
Fri, 30 Aug 2024 17:42:38 -0700 |
On Wed, Aug 28, 2024 at 5:23 AM Mark Cave-Ayland
<mark.cave-ayland@ilande.co.uk> wrote:
>
> This is a wrapper function around fifo8_peekpop_buf() that allows the caller
> to
> peek into 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>
> ---
> include/qemu/fifo8.h | 14 ++++++++++++++
> util/fifo8.c | 5 +++++
> 2 files changed, 19 insertions(+)
>
> diff --git a/include/qemu/fifo8.h b/include/qemu/fifo8.h
> index d1d06754d8..d09984b146 100644
> --- a/include/qemu/fifo8.h
> +++ b/include/qemu/fifo8.h
> @@ -76,6 +76,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
> diff --git a/util/fifo8.c b/util/fifo8.c
> index 1031ffbe7e..a8f5cea158 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);
> --
> 2.39.2
>
- Re: [PATCH 4/9] fifo8: replace fifo8_pop_bufptr() with fifo8_peekpop_bufptr() in fifo8_pop_buf(), (continued)
- [PATCH 5/9] fifo8: rename fifo8_pop_buf() to fifo8_peekpop_buf(), Mark Cave-Ayland, 2024/08/28
- [PATCH 6/9] fifo8: honour do_pop argument in fifo8_peekpop_buf(), Mark Cave-Ayland, 2024/08/28
- [PATCH 7/9] fifo8: add fifo8_peek_buf() function, Mark Cave-Ayland, 2024/08/28
- [PATCH 8/9] fifo8: introduce fifo8_peek() function, Mark Cave-Ayland, 2024/08/28
- [PATCH 9/9] tests/unit: add test-fifo unit test, Mark Cave-Ayland, 2024/08/28