[vlc-devel] [PATCH v3 10/10] core: use refcounter helper for picture pool
Romain Vimont
rom1v at videolabs.io
Tue Jul 3 08:48:01 CEST 2018
---
src/misc/picture_pool.c | 16 ++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)
diff --git a/src/misc/picture_pool.c b/src/misc/picture_pool.c
index 874a04e4d8e..d7552d35f12 100644
--- a/src/misc/picture_pool.c
+++ b/src/misc/picture_pool.c
@@ -27,10 +27,10 @@
#endif
#include <assert.h>
#include <limits.h>
-#include <stdatomic.h>
#include <stdlib.h>
#include <vlc_common.h>
+#include <vlc_atomic.h>
#include <vlc_picture_pool.h>
#include "picture.h"
@@ -46,17 +46,16 @@ struct picture_pool_t {
bool canceled;
unsigned long long available;
- atomic_ushort refs;
+ vlc_atomic_rc_t rc;
unsigned short picture_count;
picture_t *picture[];
};
static void picture_pool_Destroy(picture_pool_t *pool)
{
- if (atomic_fetch_sub_explicit(&pool->refs, 1, memory_order_release) != 1)
+ if (!vlc_atomic_rc_dec(&pool->rc))
return;
- atomic_thread_fence(memory_order_acquire);
vlc_cond_destroy(&pool->wait);
vlc_mutex_destroy(&pool->lock);
aligned_free(pool);
@@ -137,7 +136,7 @@ picture_pool_t *picture_pool_NewExtended(const picture_pool_configuration_t *cfg
pool->available = ~0ULL;
else
pool->available = (1ULL << cfg->picture_count) - 1;
- atomic_init(&pool->refs, 1);
+ vlc_atomic_rc_init(&pool->rc);
pool->picture_count = cfg->picture_count;
memcpy(pool->picture, cfg->picture,
cfg->picture_count * sizeof (picture_t *));
@@ -207,7 +206,6 @@ picture_t *picture_pool_Get(picture_pool_t *pool)
unsigned long long available;
vlc_mutex_lock(&pool->lock);
- assert(pool->refs > 0);
available = pool->available;
while (available != 0)
@@ -232,7 +230,7 @@ picture_t *picture_pool_Get(picture_pool_t *pool)
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);
+ vlc_atomic_rc_inc(&pool->rc);
}
return clone;
}
@@ -244,7 +242,6 @@ picture_t *picture_pool_Get(picture_pool_t *pool)
picture_t *picture_pool_Wait(picture_pool_t *pool)
{
vlc_mutex_lock(&pool->lock);
- assert(pool->refs > 0);
while (pool->available == 0)
{
@@ -273,7 +270,7 @@ picture_t *picture_pool_Wait(picture_pool_t *pool)
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);
+ vlc_atomic_rc_inc(&pool->rc);
}
return clone;
}
@@ -281,7 +278,6 @@ picture_t *picture_pool_Wait(picture_pool_t *pool)
void picture_pool_Cancel(picture_pool_t *pool, bool canceled)
{
vlc_mutex_lock(&pool->lock);
- assert(pool->refs > 0);
pool->canceled = canceled;
if (canceled)
--
2.18.0
More information about the vlc-devel
mailing list