FIFOs can be resized at runtime. Introduce the
fifo8_change_capacity() method to do that.
When capacity is changed, the FIFO must be reset.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/qemu/fifo8.h | 10 ++++++++++
util/fifo8.c | 7 +++++++
2 files changed, 17 insertions(+)
diff --git a/include/qemu/fifo8.h b/include/qemu/fifo8.h
index c6295c6ff0..9fe0555a24 100644
--- a/include/qemu/fifo8.h
+++ b/include/qemu/fifo8.h
@@ -31,6 +31,16 @@ void fifo8_create(Fifo8 *fifo, uint32_t capacity);
void fifo8_destroy(Fifo8 *fifo);
+/**
+ * fifo8_change_capacity:
+ * @fifo: struct Fifo8 to change the capacity
+ * @capacity: new capacity of the FIFO
+ *
+ * Change a FIFO capacity to the specified size. The FIFO is reset.
+ */
+
+void fifo8_change_capacity(Fifo8 *fifo, uint32_t capacity);
+
/**
* fifo8_push:
* @fifo: FIFO to push to
diff --git a/util/fifo8.c b/util/fifo8.c
index 2925fe5611..c453afd774 100644
--- a/util/fifo8.c
+++ b/util/fifo8.c
@@ -34,6 +34,13 @@ void fifo8_destroy(Fifo8 *fifo)
g_free(fifo->data);
}
+void fifo8_change_capacity(Fifo8 *fifo, uint32_t capacity)
+{
+ fifo->data = g_renew(uint8_t, fifo->data, capacity);
+ fifo->capacity = capacity;
+ fifo8_reset(fifo);
+}
+
void fifo8_push(Fifo8 *fifo, uint8_t data)
{
assert(fifo->num < fifo->capacity);