[vlc-commits] picture_pool: factorize the code to clone a picture for Wait/Get

Steve Lhomme git at videolan.org
Mon Aug 10 08:51:53 CEST 2020


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Mon Jul 20 14:39:44 2020 +0200| [97809aa0fa30e3cc772625f523c861d742ff992c] | committer: Steve Lhomme

picture_pool: factorize the code to clone a picture for Wait/Get

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

 src/misc/picture_pool.c | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)

diff --git a/src/misc/picture_pool.c b/src/misc/picture_pool.c
index a942a69799..988df70fb8 100644
--- a/src/misc/picture_pool.c
+++ b/src/misc/picture_pool.c
@@ -90,8 +90,13 @@ static picture_t *picture_pool_ClonePicture(picture_pool_t *pool,
     picture_t *picture = pool->picture[offset];
     uintptr_t sys = ((uintptr_t)pool) + offset;
 
-    return picture_InternalClone(picture, picture_pool_ReleaseClone,
+    picture_t *clone = picture_InternalClone(picture, picture_pool_ReleaseClone,
                                  (void*)sys);
+    if (clone != NULL) {
+        assert(clone->p_next == NULL);
+        atomic_fetch_add_explicit(&pool->refs, 1, memory_order_relaxed);
+    }
+    return clone;
 }
 
 picture_pool_t *picture_pool_New(unsigned count, picture_t *const *tab)
@@ -186,12 +191,7 @@ picture_t *picture_pool_Get(picture_pool_t *pool)
         vlc_mutex_unlock(&pool->lock);
         available &= ~(1ULL << i);
 
-        picture_t *clone = picture_pool_ClonePicture(pool, i);
-        if (clone != NULL) {
-            assert(clone->p_next == NULL);
-            atomic_fetch_add_explicit(&pool->refs, 1, memory_order_relaxed);
-        }
-        return clone;
+        return picture_pool_ClonePicture(pool, i);
     }
 
     vlc_mutex_unlock(&pool->lock);
@@ -217,12 +217,7 @@ picture_t *picture_pool_Wait(picture_pool_t *pool)
     pool->available &= ~(1ULL << i);
     vlc_mutex_unlock(&pool->lock);
 
-    picture_t *clone = picture_pool_ClonePicture(pool, i);
-    if (clone != NULL) {
-        assert(clone->p_next == NULL);
-        atomic_fetch_add_explicit(&pool->refs, 1, memory_order_relaxed);
-    }
-    return clone;
+    return picture_pool_ClonePicture(pool, i);
 }
 
 void picture_pool_Cancel(picture_pool_t *pool, bool canceled)



More information about the vlc-commits mailing list