[vlc-commits] picture_fifo: simplify the picture fifo tail handling

Steve Lhomme git at videolan.org
Wed Sep 23 16:17:52 CEST 2020


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Thu Sep 17 15:31:11 2020 +0200| [6aa2d96953ac2346c9d4314e6f914e52c0760595] | committer: Steve Lhomme

picture_fifo: simplify the picture fifo tail handling

Rather than a pointer on the last picture pointer, we use either NULL (no
tail/chain empty) or a pointer to the last picture in the chain.

Make sure that the pictures we queue don't have a p_next otherwise it would
screw the computation of the last. (the issue existed before this patch)

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=6aa2d96953ac2346c9d4314e6f914e52c0760595
---

 src/misc/picture_fifo.c | 29 ++++++++++++++++++-----------
 1 file changed, 18 insertions(+), 11 deletions(-)

diff --git a/src/misc/picture_fifo.c b/src/misc/picture_fifo.c
index f999ec1a3f..46838669e2 100644
--- a/src/misc/picture_fifo.c
+++ b/src/misc/picture_fifo.c
@@ -39,30 +39,37 @@
 struct picture_fifo_t {
     vlc_mutex_t lock;
     picture_t   *first;
-    picture_t   **last_ptr;
+    picture_t   *tail;
 };
 
 static void PictureFifoReset(picture_fifo_t *fifo)
 {
     fifo->first    = NULL;
-    fifo->last_ptr = &fifo->first;
+    fifo->tail     = NULL;
 }
 static void PictureFifoPush(picture_fifo_t *fifo, picture_t *picture)
 {
     assert(!picture->p_next);
-    *fifo->last_ptr = picture;
-    fifo->last_ptr  = &picture->p_next;
+    if (fifo->first == NULL)
+    {
+        fifo->first = picture;
+        fifo->tail  = picture;
+    }
+    else
+    {
+        fifo->tail->p_next = picture;
+        fifo->tail =  picture;
+        picture->p_next = NULL; // we're appending a picture, not a chain
+    }
 }
 static picture_t *PictureFifoPop(picture_fifo_t *fifo)
 {
-    picture_t *picture = fifo->first;
+    if (fifo->first == NULL)
+        return NULL;
 
-    if (picture) {
-        fifo->first = picture->p_next;
-        if (!fifo->first)
-            fifo->last_ptr = &fifo->first;
-        picture->p_next = NULL;
-    }
+    picture_t *picture = fifo->first;
+    fifo->first = picture->p_next;
+    picture->p_next = NULL;
     return picture;
 }
 



More information about the vlc-commits mailing list