MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / refstruct_pool_get_ext

Function refstruct_pool_get_ext

libavutil/refstruct.c:250–295  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

248}
249
250static int refstruct_pool_get_ext(void *datap, AVRefStructPool *pool)
251{
252 void *ret = NULL;
253
254 memcpy(datap, &(void *){ NULL }, sizeof(void*));
255
256 ff_mutex_lock(&pool->mutex);
257 ff_assert(!pool->uninited);
258 if (pool->available_entries) {
259 RefCount *ref = pool->available_entries;
260 ret = get_userdata(ref);
261 pool->available_entries = ref->opaque.nc;
262 ref->opaque.nc = pool;
263 atomic_init(&ref->refcount, 1);
264 }
265 ff_mutex_unlock(&pool->mutex);
266
267 if (!ret) {
268 RefCount *ref;
269 ret = av_refstruct_alloc_ext(pool->size, pool->entry_flags, pool,
270 pool->reset_cb ? pool_reset_entry : NULL);
271 if (!ret)
272 return AVERROR(ENOMEM);
273 ref = get_refcount(ret);
274 ref->free = pool_return_entry;
275 if (pool->init_cb) {
276 int err = pool->init_cb(pool->opaque, ret);
277 if (err < 0) {
278 if (pool->pool_flags & AV_REFSTRUCT_POOL_FLAG_RESET_ON_INIT_ERROR)
279 pool->reset_cb(pool->opaque, ret);
280 if (pool->pool_flags & AV_REFSTRUCT_POOL_FLAG_FREE_ON_INIT_ERROR)
281 pool->free_entry_cb(pool->opaque, ret);
282 av_free(ref);
283 return err;
284 }
285 }
286 }
287 atomic_fetch_add_explicit(&pool->refcount, 1, memory_order_relaxed);
288
289 if (pool->pool_flags & AV_REFSTRUCT_POOL_FLAG_ZERO_EVERY_TIME)
290 memset(ret, 0, pool->size);
291
292 memcpy(datap, &ret, sizeof(ret));
293
294 return 0;
295}
296
297void *av_refstruct_pool_get(AVRefStructPool *pool)
298{

Callers 1

av_refstruct_pool_getFunction · 0.85

Calls 6

ff_mutex_lockFunction · 0.85
get_userdataFunction · 0.85
ff_mutex_unlockFunction · 0.85
av_refstruct_alloc_extFunction · 0.85
get_refcountFunction · 0.85
av_freeFunction · 0.70

Tested by

no test coverage detected