[FFmpeg-devel] [PATCH 3/3] lavu/buffer: use avrefcount_template.h for AVBufferPool.

Nicolas George george at nsup.org
Sat Jun 27 18:16:46 EEST 2020


Signed-off-by: Nicolas George <george at nsup.org>
---
 libavutil/buffer.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/libavutil/buffer.c b/libavutil/buffer.c
index 7b4d0a867a..a30e289087 100644
--- a/libavutil/buffer.c
+++ b/libavutil/buffer.c
@@ -225,6 +225,14 @@ int av_buffer_realloc(AVBufferRef **pbuf, int size)
     return 0;
 }
 
+#define AVRC_TYPE AVBufferPool
+#define AVRC_PREFIX buffer_pool_
+#define AVRC_FIELD refcount
+
+static void buffer_pool_free(AVBufferPool *pool);
+
+#include "avrefcount_template.h"
+
 AVBufferPool *av_buffer_pool_init2(int size, void *opaque,
                                    AVBufferRef* (*alloc)(void *opaque, int size),
                                    void (*pool_free)(void *opaque))
@@ -241,7 +249,7 @@ AVBufferPool *av_buffer_pool_init2(int size, void *opaque,
     pool->alloc     = av_buffer_alloc; // fallback
     pool->pool_free = pool_free;
 
-    atomic_init(&pool->refcount, 1);
+    buffer_pool_init_ref_count(pool);
 
     return pool;
 }
@@ -257,7 +265,7 @@ AVBufferPool *av_buffer_pool_init(int size, AVBufferRef* (*alloc)(int size))
     pool->size     = size;
     pool->alloc    = alloc ? alloc : av_buffer_alloc;
 
-    atomic_init(&pool->refcount, 1);
+    buffer_pool_init_ref_count(pool);
 
     return pool;
 }
@@ -292,8 +300,7 @@ void av_buffer_pool_uninit(AVBufferPool **ppool)
     pool   = *ppool;
     *ppool = NULL;
 
-    if (atomic_fetch_sub_explicit(&pool->refcount, 1, memory_order_acq_rel) == 1)
-        buffer_pool_free(pool);
+    buffer_pool_unrefp(&pool);
 }
 
 static void pool_release_buffer(void *opaque, uint8_t *data)
@@ -309,8 +316,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)
-        buffer_pool_free(pool);
+    buffer_pool_unrefp(&pool);
 }
 
 /* allocate a new buffer and override its free() callback so that
@@ -364,7 +370,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);
+        buffer_pool_ref(pool);
 
     return ret;
 }
-- 
2.27.0



More information about the ffmpeg-devel mailing list