[vlc-commits] picture_pool: fix race condition

Rémi Denis-Courmont git at videolan.org
Wed Oct 29 20:27:51 CET 2014


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Oct 28 21:30:02 2014 +0200| [9e99ef07827bb2a1796770ad0b12b028b8643ede] | committer: Rémi Denis-Courmont

picture_pool: fix race condition

This makes picture_pool_Get() reentrant.

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

 src/misc/picture_pool.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/misc/picture_pool.c b/src/misc/picture_pool.c
index cfaa541..2a0f677 100644
--- a/src/misc/picture_pool.c
+++ b/src/misc/picture_pool.c
@@ -272,7 +272,9 @@ picture_t *picture_pool_Get(picture_pool_t *pool)
             continue;
 
         picture_t *picture = pool->picture[i];
-        if (atomic_load(&picture->gc.refcount) > 0)
+        uintptr_t refs = 0;
+
+        if (!atomic_compare_exchange_strong(&picture->gc.refcount, &refs, 1))
             continue;
 
         if (pool->pic_lock != NULL && pool->pic_lock(picture) != 0)
@@ -281,7 +283,6 @@ picture_t *picture_pool_Get(picture_pool_t *pool)
         /* */
         picture->p_next = NULL;
         picture->gc.p_sys->tick = pool->tick++;
-        picture_Hold(picture);
         return picture;
     }
     return NULL;



More information about the vlc-commits mailing list