[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 01/23] fifo32: add peek function
From: |
Octavian Purdila |
Subject: |
[RFC PATCH 01/23] fifo32: add peek function |
Date: |
Mon, 5 Aug 2024 13:16:56 -0700 |
Add fifo32_peek() that returns the first element from the queue
without popping it.
Signed-off-by: Octavian Purdila <tavip@google.com>
---
include/qemu/fifo32.h | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/include/qemu/fifo32.h b/include/qemu/fifo32.h
index 4e9fd1b5ef..c9befc47c8 100644
--- a/include/qemu/fifo32.h
+++ b/include/qemu/fifo32.h
@@ -140,6 +140,35 @@ static inline uint32_t fifo32_pop(Fifo32 *fifo)
return ret;
}
+/**
+ * fifo32_peek:
+ * @fifo: fifo to peek at
+ *
+ * Returns the value from the FIFO's head without poping it. Behaviour
+ * is undefined if the FIFO is empty. Clients are responsible for
+ * checking for emptiness using fifo32_is_empty().
+ *
+ * Returns: the value from the FIFO's head
+ */
+
+static inline uint32_t fifo32_peek(Fifo32 *fifo)
+{
+ uint32_t ret = 0, num;
+ const uint8_t *buf;
+ int i;
+
+ buf = fifo8_peek_buf(&fifo->fifo, 4, &num);
+ if (num != 4) {
+ return ret;
+ }
+
+ for (i = 0; i < sizeof(uint32_t); i++) {
+ ret |= buf[i] << (i * 8);
+ }
+
+ return ret;
+}
+
/**
* There is no fifo32_pop_buf() because the data is not stored in the buffer
* as a set of native-order words.
--
2.46.0.rc2.264.g509ed76dc8-goog
- [RFC PATCH 00/23] NXP i.MX RT595, ARM SVD and device model unit tests, Octavian Purdila, 2024/08/05
- [RFC PATCH 01/23] fifo32: add peek function,
Octavian Purdila <=
- [RFC PATCH 02/23] tests/unit: add fifo test, Octavian Purdila, 2024/08/05
- [RFC PATCH 03/23] scripts: add script to generate C header files from SVD XML files, Octavian Purdila, 2024/08/05
- Re: [RFC PATCH 03/23] scripts: add script to generate C header files from SVD XML files, John Snow, 2024/08/08
- Re: [RFC PATCH 03/23] scripts: add script to generate C header files from SVD XML files, Octavian Purdila, 2024/08/08
- Re: [RFC PATCH 03/23] scripts: add script to generate C header files from SVD XML files, John Snow, 2024/08/08
- Re: [RFC PATCH 03/23] scripts: add script to generate C header files from SVD XML files, Philippe Mathieu-Daudé, 2024/08/09
- Re: [RFC PATCH 03/23] scripts: add script to generate C header files from SVD XML files, Paolo Bonzini, 2024/08/09
- Re: [RFC PATCH 03/23] scripts: add script to generate C header files from SVD XML files, Daniel P . Berrangé, 2024/08/09
- Re: [RFC PATCH 03/23] scripts: add script to generate C header files from SVD XML files, Philippe Mathieu-Daudé, 2024/08/13
- Re: [RFC PATCH 03/23] scripts: add script to generate C header files from SVD XML files, Paolo Bonzini, 2024/08/09