[FFmpeg-devel] [PATCH 2/3] lavu/buffer: use avrefcount_template.h for AVBuffer.
Nicolas George
george at nsup.org
Sat Jun 27 18:16:45 EEST 2020
Signed-off-by: Nicolas George <george at nsup.org>
---
libavutil/buffer.c | 26 ++++++++++++++++++--------
1 file changed, 18 insertions(+), 8 deletions(-)
diff --git a/libavutil/buffer.c b/libavutil/buffer.c
index 38a554208a..7b4d0a867a 100644
--- a/libavutil/buffer.c
+++ b/libavutil/buffer.c
@@ -26,6 +26,19 @@
#include "mem.h"
#include "thread.h"
+#define AVRC_TYPE AVBuffer
+#define AVRC_PREFIX buffer_
+#define AVRC_FIELD refcount
+
+static inline void
+buffer_free(AVBuffer *b)
+{
+ b->free(b->opaque, b->data);
+ av_free(b);
+}
+
+#include "avrefcount_template.h"
+
AVBufferRef *av_buffer_create(uint8_t *data, int size,
void (*free)(void *opaque, uint8_t *data),
void *opaque, int flags)
@@ -42,7 +55,7 @@ AVBufferRef *av_buffer_create(uint8_t *data, int size,
buf->free = free ? free : av_buffer_default_free;
buf->opaque = opaque;
- atomic_init(&buf->refcount, 1);
+ buffer_init_ref_count(buf);
buf->flags = flags;
@@ -99,7 +112,7 @@ AVBufferRef *av_buffer_ref(AVBufferRef *buf)
*ret = *buf;
- atomic_fetch_add_explicit(&buf->buffer->refcount, 1, memory_order_relaxed);
+ buffer_ref(buf->buffer);
return ret;
}
@@ -116,10 +129,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) {
- b->free(b->opaque, b->data);
- av_freep(&b);
- }
+ buffer_unrefp(&b);
}
void av_buffer_unref(AVBufferRef **buf)
@@ -135,7 +145,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 buffer_get_ref_count(buf->buffer) == 1;
}
void *av_buffer_get_opaque(const AVBufferRef *buf)
@@ -145,7 +155,7 @@ void *av_buffer_get_opaque(const AVBufferRef *buf)
int av_buffer_get_ref_count(const AVBufferRef *buf)
{
- return atomic_load(&buf->buffer->refcount);
+ return buffer_get_ref_count(buf->buffer);
}
int av_buffer_make_writable(AVBufferRef **pbuf)
--
2.27.0
More information about the ffmpeg-devel
mailing list