[PATCH 2/9] fifo8: introduce head variable for fifo8_peekpop_bufptr()

Mark Cave-Ayland posted 9 patches 2 months, 3 weeks ago
[PATCH 2/9] fifo8: introduce head variable for fifo8_peekpop_bufptr()
Posted by Mark Cave-Ayland 2 months, 3 weeks ago
Rather than operate on fifo->head directly, introduce a new head variable which is
set to the value of fifo->head and use it instead. This is to allow future
adjustment of the head position within the internal FIFO buffer.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
 util/fifo8.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/util/fifo8.c b/util/fifo8.c
index 61bce9d9a0..5faa814a6e 100644
--- a/util/fifo8.c
+++ b/util/fifo8.c
@@ -75,11 +75,12 @@ static const uint8_t *fifo8_peekpop_bufptr(Fifo8 *fifo, uint32_t max,
                                            uint32_t *numptr, bool do_pop)
 {
     uint8_t *ret;
-    uint32_t num;
+    uint32_t num, head;
 
     assert(max > 0 && max <= fifo->num);
-    num = MIN(fifo->capacity - fifo->head, max);
-    ret = &fifo->data[fifo->head];
+    head = fifo->head;
+    num = MIN(fifo->capacity - head, max);
+    ret = &fifo->data[head];
 
     if (do_pop) {
         fifo->head += num;
-- 
2.39.2
Re: [PATCH 2/9] fifo8: introduce head variable for fifo8_peekpop_bufptr()
Posted by Octavian Purdila 2 months, 3 weeks ago
On Wed, Aug 28, 2024 at 5:23 AM Mark Cave-Ayland
<mark.cave-ayland@ilande.co.uk> wrote:
>
> Rather than operate on fifo->head directly, introduce a new head variable which is
> set to the value of fifo->head and use it instead. This is to allow future
> adjustment of the head position within the internal FIFO buffer.
>
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>

Reviewed-by: Octavian Purdila <tavip@google.com>

> ---
>  util/fifo8.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/util/fifo8.c b/util/fifo8.c
> index 61bce9d9a0..5faa814a6e 100644
> --- a/util/fifo8.c
> +++ b/util/fifo8.c
> @@ -75,11 +75,12 @@ static const uint8_t *fifo8_peekpop_bufptr(Fifo8 *fifo, uint32_t max,
>                                             uint32_t *numptr, bool do_pop)
>  {
>      uint8_t *ret;
> -    uint32_t num;
> +    uint32_t num, head;
>
>      assert(max > 0 && max <= fifo->num);
> -    num = MIN(fifo->capacity - fifo->head, max);
> -    ret = &fifo->data[fifo->head];
> +    head = fifo->head;
> +    num = MIN(fifo->capacity - head, max);
> +    ret = &fifo->data[head];
>
>      if (do_pop) {
>          fifo->head += num;
> --
> 2.39.2
>
Re: [PATCH 2/9] fifo8: introduce head variable for fifo8_peekpop_bufptr()
Posted by Alistair Francis 2 months, 3 weeks ago
On Wed, Aug 28, 2024 at 10:25 PM Mark Cave-Ayland
<mark.cave-ayland@ilande.co.uk> wrote:
>
> Rather than operate on fifo->head directly, introduce a new head variable which is
> set to the value of fifo->head and use it instead. This is to allow future
> adjustment of the head position within the internal FIFO buffer.
>
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Alistair

> ---
>  util/fifo8.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/util/fifo8.c b/util/fifo8.c
> index 61bce9d9a0..5faa814a6e 100644
> --- a/util/fifo8.c
> +++ b/util/fifo8.c
> @@ -75,11 +75,12 @@ static const uint8_t *fifo8_peekpop_bufptr(Fifo8 *fifo, uint32_t max,
>                                             uint32_t *numptr, bool do_pop)
>  {
>      uint8_t *ret;
> -    uint32_t num;
> +    uint32_t num, head;
>
>      assert(max > 0 && max <= fifo->num);
> -    num = MIN(fifo->capacity - fifo->head, max);
> -    ret = &fifo->data[fifo->head];
> +    head = fifo->head;
> +    num = MIN(fifo->capacity - head, max);
> +    ret = &fifo->data[head];
>
>      if (do_pop) {
>          fifo->head += num;
> --
> 2.39.2
>
>