mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-09 02:24:58 -06:00
fifo8: add skip parameter to fifo8_peekpop_bufptr()
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> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Octavian Purdila <tavip@google.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org> Message-ID: <20240828122258.928947-4-mark.cave-ayland@ilande.co.uk> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
This commit is contained in:
parent
0b73afec0e
commit
e8b33243bb
1 changed files with 7 additions and 5 deletions
12
util/fifo8.c
12
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,
|
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;
|
uint8_t *ret;
|
||||||
uint32_t num, head;
|
uint32_t num, head;
|
||||||
|
|
||||||
assert(max > 0 && max <= fifo->num);
|
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);
|
num = MIN(fifo->capacity - head, max);
|
||||||
ret = &fifo->data[head];
|
ret = &fifo->data[head];
|
||||||
|
|
||||||
if (do_pop) {
|
if (do_pop) {
|
||||||
fifo->head += num;
|
fifo->head = head + num;
|
||||||
fifo->head %= fifo->capacity;
|
fifo->head %= fifo->capacity;
|
||||||
fifo->num -= num;
|
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)
|
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)
|
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)
|
uint32_t fifo8_pop_buf(Fifo8 *fifo, uint8_t *dest, uint32_t destlen)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue