diff options
Diffstat (limited to 'libavutil/buffer.c')
-rw-r--r-- | libavutil/buffer.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/libavutil/buffer.c b/libavutil/buffer.c index 54590be566..6612183094 100644 --- a/libavutil/buffer.c +++ b/libavutil/buffer.c @@ -24,6 +24,7 @@ #include "buffer_internal.h" #include "common.h" #include "mem.h" +#include "refcount.h" #include "thread.h" static AVBufferRef *buffer_create(AVBuffer *buf, uint8_t *data, size_t size, @@ -37,7 +38,7 @@ static AVBufferRef *buffer_create(AVBuffer *buf, uint8_t *data, size_t size, buf->free = free ? free : av_buffer_default_free; buf->opaque = opaque; - atomic_init(&buf->refcount, 1); + av_refcount_init(&buf->rc, NULL, NULL); buf->flags = flags; @@ -109,7 +110,7 @@ AVBufferRef *av_buffer_ref(const AVBufferRef *buf) *ret = *buf; - atomic_fetch_add_explicit(&buf->buffer->refcount, 1, memory_order_relaxed); + av_refcount_inc(&buf->buffer->rc); return ret; } @@ -126,7 +127,7 @@ static void buffer_replace(AVBufferRef **dst, AVBufferRef **src) } else av_freep(dst); - if (atomic_fetch_sub_explicit(&b->refcount, 1, memory_order_acq_rel) == 1) { + if (!av_refcount_dec(&bc->rc)) { /* b->free below might already free the structure containing *b, * so we have to read the flag now to avoid use-after-free. */ int free_avbuffer = !(b->flags_internal & BUFFER_FLAG_NO_FREE); @@ -149,7 +150,7 @@ int av_buffer_is_writable(const AVBufferRef *buf) if (buf->buffer->flags & AV_BUFFER_FLAG_READONLY) return 0; - return atomic_load(&buf->buffer->refcount) == 1; + return av_refcount_exclusive(&buf->buffer->rc); } void *av_buffer_get_opaque(const AVBufferRef *buf) @@ -159,7 +160,8 @@ void *av_buffer_get_opaque(const AVBufferRef *buf) int av_buffer_get_ref_count(const AVBufferRef *buf) { - return atomic_load(&buf->buffer->refcount); + //return atomic_load(&buf->buffer->refcount); + return 1; } int av_buffer_make_writable(AVBufferRef **pbuf) @@ -272,7 +274,7 @@ AVBufferPool *av_buffer_pool_init2(size_t size, void *opaque, pool->alloc = av_buffer_alloc; // fallback pool->pool_free = pool_free; - atomic_init(&pool->refcount, 1); + av_refcount_init(&pool->rc, NULL, NULL); return pool; } @@ -288,7 +290,7 @@ AVBufferPool *av_buffer_pool_init(size_t size, AVBufferRef* (*alloc)(size_t size pool->size = size; pool->alloc = alloc ? alloc : av_buffer_alloc; - atomic_init(&pool->refcount, 1); + av_refcount_init(&pool->rc, NULL, NULL); return pool; } @@ -332,7 +334,7 @@ void av_buffer_pool_uninit(AVBufferPool **ppool) buffer_pool_flush(pool); ff_mutex_unlock(&pool->mutex); - if (atomic_fetch_sub_explicit(&pool->refcount, 1, memory_order_acq_rel) == 1) + if (av_refcount_dec(&pool->rc) == 1) buffer_pool_free(pool); } @@ -349,7 +351,7 @@ static void pool_release_buffer(void *opaque, uint8_t *data) pool->pool = buf; ff_mutex_unlock(&pool->mutex); - if (atomic_fetch_sub_explicit(&pool->refcount, 1, memory_order_acq_rel) == 1) + if (!av_refcount_dec(&pool->rc)) buffer_pool_free(pool); } @@ -406,7 +408,7 @@ AVBufferRef *av_buffer_pool_get(AVBufferPool *pool) ff_mutex_unlock(&pool->mutex); if (ret) - atomic_fetch_add_explicit(&pool->refcount, 1, memory_order_relaxed); + av_refcount_inc(&pool->rc); return ret; } |