[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 3/9] fifo8: add skip parameter to fifo8_peekpop_bufptr()
|
From: |
Mark Cave-Ayland |
|
Subject: |
[PATCH 3/9] fifo8: add skip parameter to fifo8_peekpop_bufptr() |
|
Date: |
Wed, 28 Aug 2024 13:22:52 +0100 |
The skip parameter specifies the number of bytes to be skipped from the current
FIFO head before the peek or pop operation.
Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
util/fifo8.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/util/fifo8.c b/util/fifo8.c
index 5faa814a6e..62d6430b05 100644
--- a/util/fifo8.c
+++ b/util/fifo8.c
@@ -72,18 +72,20 @@ uint8_t fifo8_pop(Fifo8 *fifo)
}
static const uint8_t *fifo8_peekpop_bufptr(Fifo8 *fifo, uint32_t max,
- uint32_t *numptr, bool do_pop)
+ uint32_t skip, uint32_t *numptr,
+ bool do_pop)
{
uint8_t *ret;
uint32_t num, head;
assert(max > 0 && max <= fifo->num);
- head = fifo->head;
+ assert(skip <= fifo->num);
+ head = (fifo->head + skip) % fifo->capacity;
num = MIN(fifo->capacity - head, max);
ret = &fifo->data[head];
if (do_pop) {
- fifo->head += num;
+ fifo->head = head + num;
fifo->head %= fifo->capacity;
fifo->num -= num;
}
@@ -95,12 +97,12 @@ static const uint8_t *fifo8_peekpop_bufptr(Fifo8 *fifo,
uint32_t max,
const uint8_t *fifo8_peek_bufptr(Fifo8 *fifo, uint32_t max, uint32_t *numptr)
{
- return fifo8_peekpop_bufptr(fifo, max, numptr, false);
+ return fifo8_peekpop_bufptr(fifo, max, 0, numptr, false);
}
const uint8_t *fifo8_pop_bufptr(Fifo8 *fifo, uint32_t max, uint32_t *numptr)
{
- return fifo8_peekpop_bufptr(fifo, max, numptr, true);
+ return fifo8_peekpop_bufptr(fifo, max, 0, numptr, true);
}
uint32_t fifo8_pop_buf(Fifo8 *fifo, uint8_t *dest, uint32_t destlen)
--
2.39.2
- [PATCH 0/9] fifo8: add fifo8_peek(), fifo8_peek_buf() and tests, Mark Cave-Ayland, 2024/08/28
- [PATCH 1/9] fifo8: rename fifo8_peekpop_buf() to fifo8_peekpop_bufptr(), Mark Cave-Ayland, 2024/08/28
- [PATCH 2/9] fifo8: introduce head variable for fifo8_peekpop_bufptr(), Mark Cave-Ayland, 2024/08/28
- [PATCH 3/9] fifo8: add skip parameter to fifo8_peekpop_bufptr(),
Mark Cave-Ayland <=
- [PATCH 4/9] fifo8: replace fifo8_pop_bufptr() with fifo8_peekpop_bufptr() in fifo8_pop_buf(), Mark Cave-Ayland, 2024/08/28
- [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