FFmpeg
|
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... | |
RefCount * | available_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 |
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.
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().
FFRefStructOpaque FFRefStructPool::opaque |
Definition at line 185 of file refstruct.c.
Referenced by ff_refstruct_pool_alloc_ext(), ff_refstruct_pool_alloc_ext_c(), pool_free(), pool_free_entry(), pool_reset_entry(), and refstruct_pool_get_ext().
int(* FFRefStructPool::init_cb) (FFRefStructOpaque opaque, void *obj) |
Definition at line 186 of file refstruct.c.
Referenced by ff_refstruct_pool_alloc_ext(), ff_refstruct_pool_alloc_ext_c(), and refstruct_pool_get_ext().
void(* FFRefStructPool::reset_cb) (FFRefStructOpaque opaque, void *obj) |
Definition at line 187 of file refstruct.c.
Referenced by ff_refstruct_pool_alloc_ext(), ff_refstruct_pool_alloc_ext_c(), pool_reset_entry(), and refstruct_pool_get_ext().
void(* FFRefStructPool::free_entry_cb) (FFRefStructOpaque opaque, void *obj) |
Definition at line 188 of file refstruct.c.
Referenced by ff_refstruct_pool_alloc_ext(), ff_refstruct_pool_alloc_ext_c(), pool_free_entry(), and refstruct_pool_get_ext().
void(* FFRefStructPool::free_cb) (FFRefStructOpaque opaque) |
Definition at line 189 of file refstruct.c.
Referenced by ff_refstruct_pool_alloc_ext(), ff_refstruct_pool_alloc_ext_c(), and pool_free().
int FFRefStructPool::uninited |
Definition at line 191 of file refstruct.c.
Referenced by pool_return_entry(), refstruct_pool_get_ext(), and refstruct_pool_uninit().
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().
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().
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().
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().
AVMutex FFRefStructPool::mutex |
Definition at line 205 of file refstruct.c.
Referenced by ff_refstruct_pool_alloc_ext_c(), pool_free(), pool_return_entry(), refstruct_pool_get_ext(), and refstruct_pool_uninit().