diff mbox series

[8/9] fifo8: introduce fifo8_peek() function

Message ID 20240828122258.928947-9-mark.cave-ayland@ilande.co.uk (mailing list archive)
State New
Headers show
Series fifo8: add fifo8_peek(), fifo8_peek_buf() and tests | expand

Commit Message

Mark Cave-Ayland Aug. 28, 2024, 12:22 p.m. UTC
This allows uses to peek the byte at the current head of the FIFO.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
 include/qemu/fifo8.h | 11 +++++++++++
 util/fifo8.c         |  6 ++++++
 2 files changed, 17 insertions(+)

Comments

Alistair Francis Aug. 29, 2024, 11:59 p.m. UTC | #1
On Wed, Aug 28, 2024 at 10:26 PM Mark Cave-Ayland
<mark.cave-ayland@ilande.co.uk> wrote:
>
> This allows uses to peek the byte at the current head of the FIFO.
>
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Alistair

> ---
>  include/qemu/fifo8.h | 11 +++++++++++
>  util/fifo8.c         |  6 ++++++
>  2 files changed, 17 insertions(+)
>
> diff --git a/include/qemu/fifo8.h b/include/qemu/fifo8.h
> index d09984b146..4f768d4ee3 100644
> --- a/include/qemu/fifo8.h
> +++ b/include/qemu/fifo8.h
> @@ -62,6 +62,17 @@ void fifo8_push_all(Fifo8 *fifo, const uint8_t *data, uint32_t num);
>   */
>  uint8_t fifo8_pop(Fifo8 *fifo);
>
> +/**
> + * fifo8_peek:
> + * @fifo: fifo to peek from
> + *
> + * Peek the data byte at the current head of the FIFO. Clients are responsible
> + * for checking for emptyness using fifo8_is_empty().
> + *
> + * Returns: The peeked data byte.
> + */
> +uint8_t fifo8_peek(Fifo8 *fifo);
> +
>  /**
>   * fifo8_pop_buf:
>   * @fifo: FIFO to pop from
> diff --git a/util/fifo8.c b/util/fifo8.c
> index a8f5cea158..a26da66ad2 100644
> --- a/util/fifo8.c
> +++ b/util/fifo8.c
> @@ -71,6 +71,12 @@ uint8_t fifo8_pop(Fifo8 *fifo)
>      return ret;
>  }
>
> +uint8_t fifo8_peek(Fifo8 *fifo)
> +{
> +    assert(fifo->num > 0);
> +    return fifo->data[fifo->head];
> +}
> +
>  static const uint8_t *fifo8_peekpop_bufptr(Fifo8 *fifo, uint32_t max,
>                                             uint32_t skip, uint32_t *numptr,
>                                             bool do_pop)
> --
> 2.39.2
>
>
Octavian Purdila Aug. 31, 2024, 12:44 a.m. UTC | #2
On Wed, Aug 28, 2024 at 5:23 AM Mark Cave-Ayland
<mark.cave-ayland@ilande.co.uk> wrote:
>
> This allows uses to peek the byte at the current head of the FIFO.
>
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>

Reviewed-by: Octavian Purdila <tavip@google.com>

> ---
>  include/qemu/fifo8.h | 11 +++++++++++
>  util/fifo8.c         |  6 ++++++
>  2 files changed, 17 insertions(+)
>
> diff --git a/include/qemu/fifo8.h b/include/qemu/fifo8.h
> index d09984b146..4f768d4ee3 100644
> --- a/include/qemu/fifo8.h
> +++ b/include/qemu/fifo8.h
> @@ -62,6 +62,17 @@ void fifo8_push_all(Fifo8 *fifo, const uint8_t *data, uint32_t num);
>   */
>  uint8_t fifo8_pop(Fifo8 *fifo);
>
> +/**
> + * fifo8_peek:
> + * @fifo: fifo to peek from
> + *
> + * Peek the data byte at the current head of the FIFO. Clients are responsible
> + * for checking for emptyness using fifo8_is_empty().
> + *
> + * Returns: The peeked data byte.
> + */
> +uint8_t fifo8_peek(Fifo8 *fifo);
> +
>  /**
>   * fifo8_pop_buf:
>   * @fifo: FIFO to pop from
> diff --git a/util/fifo8.c b/util/fifo8.c
> index a8f5cea158..a26da66ad2 100644
> --- a/util/fifo8.c
> +++ b/util/fifo8.c
> @@ -71,6 +71,12 @@ uint8_t fifo8_pop(Fifo8 *fifo)
>      return ret;
>  }
>
> +uint8_t fifo8_peek(Fifo8 *fifo)
> +{
> +    assert(fifo->num > 0);
> +    return fifo->data[fifo->head];
> +}
> +
>  static const uint8_t *fifo8_peekpop_bufptr(Fifo8 *fifo, uint32_t max,
>                                             uint32_t skip, uint32_t *numptr,
>                                             bool do_pop)
> --
> 2.39.2
>
diff mbox series

Patch

diff --git a/include/qemu/fifo8.h b/include/qemu/fifo8.h
index d09984b146..4f768d4ee3 100644
--- a/include/qemu/fifo8.h
+++ b/include/qemu/fifo8.h
@@ -62,6 +62,17 @@  void fifo8_push_all(Fifo8 *fifo, const uint8_t *data, uint32_t num);
  */
 uint8_t fifo8_pop(Fifo8 *fifo);
 
+/**
+ * fifo8_peek:
+ * @fifo: fifo to peek from
+ *
+ * Peek the data byte at the current head of the FIFO. Clients are responsible
+ * for checking for emptyness using fifo8_is_empty().
+ *
+ * Returns: The peeked data byte.
+ */
+uint8_t fifo8_peek(Fifo8 *fifo);
+
 /**
  * fifo8_pop_buf:
  * @fifo: FIFO to pop from
diff --git a/util/fifo8.c b/util/fifo8.c
index a8f5cea158..a26da66ad2 100644
--- a/util/fifo8.c
+++ b/util/fifo8.c
@@ -71,6 +71,12 @@  uint8_t fifo8_pop(Fifo8 *fifo)
     return ret;
 }
 
+uint8_t fifo8_peek(Fifo8 *fifo)
+{
+    assert(fifo->num > 0);
+    return fifo->data[fifo->head];
+}
+
 static const uint8_t *fifo8_peekpop_bufptr(Fifo8 *fifo, uint32_t max,
                                            uint32_t skip, uint32_t *numptr,
                                            bool do_pop)