32#ifndef REFSTRUCT_CHECKED
36#define REFSTRUCT_CHECKED (ASSERT_LEVEL >= 1)
40#define ff_assert(cond) av_assert0(cond)
42#define ff_assert(cond) ((void)0)
45#define REFSTRUCT_COOKIE AV_NE((uint64_t)MKBETAG('R', 'e', 'f', 'S') << 32 | MKBETAG('t', 'r', 'u', 'c'), \
46 MKTAG('R', 'e', 'f', 'S') | (uint64_t)MKTAG('t', 'r', 'u', 'c') << 32)
49#define REFCOUNT_OFFSET FFALIGN(sizeof(RefCount), FFMAX(ALIGN_64, _Alignof(max_align_t)))
51#define REFCOUNT_OFFSET FFALIGN(sizeof(RefCount), ALIGN_64)
94 ref->free_cb = free_cb;
115 memset(obj, 0,
size);
125 memcpy(&obj, objp,
sizeof(obj));
128 memcpy(objp, &(
void *){
NULL },
sizeof(obj));
133 ref->free_cb(
ref->opaque, obj);
163 memcpy(&
dst, dstp,
sizeof(
dst));
170 memcpy(dstp, &
dst,
sizeof(
dst));
254 memcpy(datap, &(
void *){
NULL },
sizeof(
void*));
262 ref->opaque.nc = pool;
290 memset(ret, 0, pool->
size);
292 memcpy(datap, &ret,
sizeof(ret));
329 void *next =
entry->opaque.nc;
361#define COMMON_FLAGS AV_REFSTRUCT_POOL_FLAG_NO_ZEROING
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
simple assert() macros that are a bit more flexible than ISO C assert().
#define flags(name, subs,...)
#define atomic_fetch_add_explicit(object, operand, order)
#define atomic_load_explicit(object, order)
intptr_t atomic_uintptr_t
#define atomic_init(obj, value)
#define atomic_fetch_sub_explicit(object, operand, order)
static int ff_mutex_unlock(AVMutex *mutex)
static int ff_mutex_lock(AVMutex *mutex)
static int ff_mutex_destroy(AVMutex *mutex)
static int ff_mutex_init(AVMutex *mutex, const void *attr)
Utility Preprocessor macros.
Memory handling functions.
AVRefStructPool * av_refstruct_pool_alloc(size_t size, unsigned flags)
Equivalent to av_refstruct_pool_alloc(size, flags, NULL, NULL, NULL, NULL, NULL)
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
void av_refstruct_replace(void *dstp, const void *src)
Ensure *dstp refers to the same object as src.
static RefCount * get_refcount(void *obj)
const void * av_refstruct_ref_c(const void *obj)
Analog of av_refstruct_ref(), but for constant objects.
static void pool_free_entry(AVRefStructPool *pool, RefCount *ref)
static void refcount_init(RefCount *ref, AVRefStructOpaque opaque, void(*free_cb)(AVRefStructOpaque opaque, void *obj))
static void * get_userdata(void *buf)
static const RefCount * cget_refcount(const void *obj)
void * av_refstruct_pool_get(AVRefStructPool *pool)
Get an object from the pool, reusing an old one from the pool when available.
void * av_refstruct_alloc_ext_c(size_t size, unsigned flags, AVRefStructOpaque opaque, void(*free_cb)(AVRefStructOpaque opaque, void *obj))
Allocate a refcounted object of usable size size managed via the RefStruct API.
int av_refstruct_exclusive(const void *obj)
Check whether the reference count of an object managed via this API is 1.
void * av_refstruct_ref(void *obj)
Create a new reference to an object managed via this API, i.e.
static void pool_free(AVRefStructPool *pool)
AVRefStructPool * av_refstruct_pool_alloc_ext_c(size_t size, unsigned flags, AVRefStructOpaque opaque, int(*init_cb)(AVRefStructOpaque opaque, void *obj), void(*reset_cb)(AVRefStructOpaque opaque, void *obj), void(*free_entry_cb)(AVRefStructOpaque opaque, void *obj), void(*free_cb)(AVRefStructOpaque opaque))
Allocate an AVRefStructPool, potentially using complex callbacks.
static void pool_unref(void *ref)
Hint: The content of pool_unref() and refstruct_pool_uninit() could currently be merged; they are onl...
static void pool_return_entry(void *ref_)
static void pool_reset_entry(AVRefStructOpaque opaque, void *entry)
static int refstruct_pool_get_ext(void *datap, AVRefStructPool *pool)
static void refstruct_pool_uninit(AVRefStructOpaque unused, void *obj)
#define AV_REFSTRUCT_POOL_FLAG_ZERO_EVERY_TIME
If this flag is set, the entries will be zeroed before being returned to the user (after the init or ...
#define AV_REFSTRUCT_POOL_FLAG_FREE_ON_INIT_ERROR
If this flag is set and both init_cb and free_entry_cb callbacks are provided, then free_cb will be c...
#define AV_REFSTRUCT_POOL_FLAG_RESET_ON_INIT_ERROR
If this flag is set and both init_cb and reset_cb callbacks are provided, then reset_cb will be calle...
static void * av_refstruct_alloc_ext(size_t size, unsigned flags, void *opaque, void(*free_cb)(AVRefStructOpaque opaque, void *obj))
A wrapper around av_refstruct_alloc_ext_c() for the common case of a non-const qualified opaque.
static AVRefStructPool * av_refstruct_pool_alloc_ext(size_t size, unsigned flags, void *opaque, int(*init_cb)(AVRefStructOpaque opaque, void *obj), void(*reset_cb)(AVRefStructOpaque opaque, void *obj), void(*free_entry_cb)(AVRefStructOpaque opaque, void *obj), void(*free_cb)(AVRefStructOpaque opaque))
A wrapper around av_refstruct_pool_alloc_ext_c() for the common case of a non-const qualified opaque.
#define AV_REFSTRUCT_FLAG_NO_ZEROING
If this flag is set in av_refstruct_alloc_ext_c(), the object will not be initially zeroed.
AVRefStructPool is an API for a thread-safe pool of objects managed via the RefStruct API.
int(* init_cb)(AVRefStructOpaque opaque, void *obj)
void(* reset_cb)(AVRefStructOpaque opaque, void *obj)
void(* free_cb)(AVRefStructOpaque opaque)
RefCount * available_entries
This is a linked list of available entries; the RefCount's opaque pointer is used as next pointer for...
void(* free_entry_cb)(AVRefStructOpaque opaque, void *obj)
atomic_uintptr_t refcount
The number of outstanding entries not in available_entries.
atomic_uintptr_t refcount
An uintptr_t is big enough to hold the address of every reference, so no overflow can happen when inc...
void(* free_cb)(AVRefStructOpaque opaque, void *obj)
static int ref[MAX_W *MAX_W]
RefStruct is an API for creating reference-counted objects with minimal overhead.