FFmpeg
Data Fields
FFRefStructPool Struct Reference

FFRefStructPool is an API for a thread-safe pool of objects managed via the RefStruct API. More...

Data Fields

size_t size
 
FFRefStructOpaque opaque
 
int(* init_cb )(FFRefStructOpaque opaque, void *obj)
 
void(* reset_cb )(FFRefStructOpaque opaque, void *obj)
 
void(* free_entry_cb )(FFRefStructOpaque opaque, void *obj)
 
void(* free_cb )(FFRefStructOpaque opaque)
 
int uninited
 
unsigned entry_flags
 
unsigned pool_flags
 
atomic_uintptr_t refcount
 The number of outstanding entries not in available_entries. More...
 
RefCountavailable_entries
 This is a linked list of available entries; the RefCount's opaque pointer is used as next pointer for available entries. More...
 
AVMutex mutex
 

Detailed Description

FFRefStructPool is an API for a thread-safe pool of objects managed via the RefStruct API.

Frequently allocating and freeing large or complicated objects may be slow and wasteful. This API is meant to solve this in cases when the caller needs a set of interchangable objects.

At the beginning, the user must call allocate the pool via ff_refstruct_pool_alloc() or its analogue ff_refstruct_pool_alloc_ext(). Then whenever an object is needed, call ff_refstruct_pool_get() to get a new or reused object from the pool. This new object works in all aspects the same way as the ones created by ff_refstruct_alloc_ext(). However, when the last reference to this object is unreferenced, it is (optionally) reset and returned to the pool instead of being freed and will be reused for subsequent ff_refstruct_pool_get() calls.

When the caller is done with the pool and no longer needs to create any new objects, ff_refstruct_pool_uninit() must be called to mark the pool as freeable. Then entries returned to the pool will then be freed. Once all the entries are freed, the pool will automatically be freed.

Allocating and releasing objects with this API is thread-safe as long as the user-supplied callbacks (if provided) are thread-safe. The buffer pool. This structure is opaque and not meant to be accessed directly. It is allocated with the allocators below and freed with ff_refstruct_pool_uninit().

Definition at line 183 of file refstruct.c.

Field Documentation

◆ size

size_t FFRefStructPool::size

Definition at line 184 of file refstruct.c.

Referenced by ff_refstruct_pool_alloc_ext_c(), and refstruct_pool_get_ext().

◆ opaque

FFRefStructOpaque FFRefStructPool::opaque

◆ init_cb

int(* FFRefStructPool::init_cb) (FFRefStructOpaque opaque, void *obj)

◆ reset_cb

void(* FFRefStructPool::reset_cb) (FFRefStructOpaque opaque, void *obj)

◆ free_entry_cb

void(* FFRefStructPool::free_entry_cb) (FFRefStructOpaque opaque, void *obj)

◆ free_cb

void(* FFRefStructPool::free_cb) (FFRefStructOpaque opaque)

◆ uninited

int FFRefStructPool::uninited

Definition at line 191 of file refstruct.c.

Referenced by pool_return_entry(), refstruct_pool_get_ext(), and refstruct_pool_uninit().

◆ entry_flags

unsigned FFRefStructPool::entry_flags

Definition at line 192 of file refstruct.c.

Referenced by ff_refstruct_pool_alloc_ext_c(), and refstruct_pool_get_ext().

◆ pool_flags

unsigned FFRefStructPool::pool_flags

Definition at line 193 of file refstruct.c.

Referenced by ff_refstruct_pool_alloc_ext_c(), and refstruct_pool_get_ext().

◆ refcount

atomic_uintptr_t FFRefStructPool::refcount

The number of outstanding entries not in available_entries.

Definition at line 196 of file refstruct.c.

Referenced by ff_refstruct_pool_alloc_ext_c(), pool_return_entry(), pool_unref(), and refstruct_pool_get_ext().

◆ available_entries

RefCount* FFRefStructPool::available_entries

This is a linked list of available entries; the RefCount's opaque pointer is used as next pointer for available entries.

While the entries are in use, the opaque is a pointer to the corresponding FFRefStructPool.

Definition at line 204 of file refstruct.c.

Referenced by pool_return_entry(), refstruct_pool_get_ext(), and refstruct_pool_uninit().

◆ mutex

AVMutex FFRefStructPool::mutex

The documentation for this struct was generated from the following file: