[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 7/7] util/fifo8: Introduce fifo8_discard()
From: |
Philippe Mathieu-Daudé |
Subject: |
[PATCH v2 7/7] util/fifo8: Introduce fifo8_discard() |
Date: |
Mon, 22 Jul 2024 18:07:45 +0200 |
Add the fifo8_discard() helper for clarity.
It is a simple wrapper over fifo8_pop_buf().
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/qemu/fifo8.h | 8 ++++++++
hw/scsi/esp.c | 2 +-
util/fifo8.c | 6 ++++++
3 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/include/qemu/fifo8.h b/include/qemu/fifo8.h
index 21c7a22937..53bafabd25 100644
--- a/include/qemu/fifo8.h
+++ b/include/qemu/fifo8.h
@@ -129,6 +129,14 @@ const uint8_t *fifo8_pop_constbuf(Fifo8 *fifo, uint32_t
max, uint32_t *numptr);
*/
const uint8_t *fifo8_peek_constbuf(Fifo8 *fifo, uint32_t max, uint32_t
*numptr);
+/**
+ * fifo8_discard:
+ * @fifo: FIFO to consume bytes
+ *
+ * Discard (consume) bytes from a FIFO.
+ */
+void fifo8_discard(Fifo8 *fifo, uint32_t len);
+
/**
* fifo8_reset:
* @fifo: FIFO to reset
diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c
index cec847b54a..c703fa7351 100644
--- a/hw/scsi/esp.c
+++ b/hw/scsi/esp.c
@@ -351,7 +351,7 @@ static void do_message_phase(ESPState *s)
/* Ignore extended messages for now */
if (s->cmdfifo_cdb_offset) {
int len = MIN(s->cmdfifo_cdb_offset, fifo8_num_used(&s->cmdfifo));
- fifo8_pop_buf(&s->cmdfifo, NULL, len);
+ fifo8_discard(&s->cmdfifo, len);
s->cmdfifo_cdb_offset = 0;
}
}
diff --git a/util/fifo8.c b/util/fifo8.c
index 6610b79182..ea39ca2552 100644
--- a/util/fifo8.c
+++ b/util/fifo8.c
@@ -131,6 +131,12 @@ uint32_t fifo8_pop_buf(Fifo8 *fifo, uint8_t *dest,
uint32_t destlen)
return n1 + n2;
}
+void fifo8_consume(Fifo8 *fifo, uint32_t len)
+{
+ len -= fifo8_pop_buf(fifo, NULL, len);
+ assert(len == 0);
+}
+
bool fifo8_is_empty(Fifo8 *fifo)
{
return (fifo->num == 0);
--
2.41.0