Commit 9e99ef07 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

picture_pool: fix race condition

This makes picture_pool_Get() reentrant.
parent 364e73c3
...@@ -272,7 +272,9 @@ picture_t *picture_pool_Get(picture_pool_t *pool) ...@@ -272,7 +272,9 @@ picture_t *picture_pool_Get(picture_pool_t *pool)
continue; continue;
picture_t *picture = pool->picture[i]; 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; continue;
if (pool->pic_lock != NULL && pool->pic_lock(picture) != 0) if (pool->pic_lock != NULL && pool->pic_lock(picture) != 0)
...@@ -281,7 +283,6 @@ picture_t *picture_pool_Get(picture_pool_t *pool) ...@@ -281,7 +283,6 @@ picture_t *picture_pool_Get(picture_pool_t *pool)
/* */ /* */
picture->p_next = NULL; picture->p_next = NULL;
picture->gc.p_sys->tick = pool->tick++; picture->gc.p_sys->tick = pool->tick++;
picture_Hold(picture);
return picture; return picture;
} }
return NULL; return NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment