Go to the documentation of this file.
19 #include <stdatomic.h>
30 #ifndef REFSTRUCT_CHECKED
32 #define ASSERT_LEVEL 0
34 #define REFSTRUCT_CHECKED (ASSERT_LEVEL >= 1)
38 #define ff_assert(cond) av_assert0(cond)
40 #define ff_assert(cond) ((void)0)
43 #define REFSTRUCT_COOKIE AV_NE((uint64_t)MKBETAG('R', 'e', 'f', 'S') << 32 | MKBETAG('t', 'r', 'u', 'c'), \
44 MKTAG('R', 'e', 'f', 'S') | (uint64_t)MKTAG('t', 'r', 'u', 'c') << 32)
46 #if __STDC_VERSION__ >= 201112L
47 #define REFCOUNT_OFFSET FFALIGN(sizeof(RefCount), FFMAX3(STRIDE_ALIGN, 16, _Alignof(max_align_t)))
49 #define REFCOUNT_OFFSET FFALIGN(sizeof(RefCount), FFMAX(STRIDE_ALIGN, 16))
91 ref->free_cb = free_cb;
111 memset(obj, 0,
size);
121 memcpy(&obj, objp,
sizeof(obj));
124 memcpy(objp, &(
void *){
NULL },
sizeof(obj));
129 ref->free_cb(
ref->opaque, obj);
159 memcpy(&dst, dstp,
sizeof(dst));
166 memcpy(dstp, &dst,
sizeof(dst));
void * ff_refstruct_ref(void *obj)
Create a new reference to an object managed via this API, i.e.
void(* free_cb)(FFRefStructOpaque opaque, void *obj)
void * ff_refstruct_alloc_ext_c(size_t size, unsigned flags, FFRefStructOpaque opaque, void(*free_cb)(FFRefStructOpaque opaque, void *obj))
Allocate a refcounted object of usable size size managed via the RefStruct API.
RefStruct is an API for creating reference-counted objects with minimal overhead.
intptr_t atomic_uintptr_t
atomic_uintptr_t refcount
An uintptr_t is big enough to hold the address of every reference, so no overflow can happen when inc...
int ff_refstruct_exclusive(const void *obj)
Check whether the reference count of an object managed via this API is 1.
const void * ff_refstruct_ref_c(const void *obj)
Analog of ff_refstruct_ref(), but for constant objects.
#define atomic_fetch_sub_explicit(object, operand, order)
#define atomic_load_explicit(object, order)
#define atomic_fetch_add_explicit(object, operand, order)
static void * get_userdata(void *buf)
void ff_refstruct_replace(void *dstp, const void *src)
Ensure *dstp refers to the same object as src.
static RefCount * get_refcount(void *obj)
static int ref[MAX_W *MAX_W]
static const RefCount * cget_refcount(const void *obj)
#define FF_REFSTRUCT_FLAG_NO_ZEROING
If this flag is set in ff_refstruct_alloc_ext_c(), the object will not be initially zeroed.
#define flags(name, subs,...)
#define atomic_init(obj, value)
static void refcount_init(RefCount *ref, FFRefStructOpaque opaque, void(*free_cb)(FFRefStructOpaque opaque, void *obj))
void ff_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...