Lines Matching refs:pool
263 AVBufferPool *pool = av_mallocz(sizeof(*pool));
264 if (!pool)
267 ff_mutex_init(&pool->mutex, NULL);
269 pool->size = size;
270 pool->opaque = opaque;
271 pool->alloc2 = alloc;
272 pool->alloc = av_buffer_alloc; // fallback
273 pool->pool_free = pool_free;
275 atomic_init(&pool->refcount, 1);
277 return pool;
282 AVBufferPool *pool = av_mallocz(sizeof(*pool));
283 if (!pool)
286 ff_mutex_init(&pool->mutex, NULL);
288 pool->size = size;
289 pool->alloc = alloc ? alloc : av_buffer_alloc;
291 atomic_init(&pool->refcount, 1);
293 return pool;
296 static void buffer_pool_flush(AVBufferPool *pool)
298 while (pool->pool) {
299 BufferPoolEntry *buf = pool->pool;
300 pool->pool = buf->next;
308 * This function gets called when the pool has been uninited and
311 static void buffer_pool_free(AVBufferPool *pool)
313 buffer_pool_flush(pool);
314 ff_mutex_destroy(&pool->mutex);
316 if (pool->pool_free)
317 pool->pool_free(pool->opaque);
319 av_freep(&pool);
324 AVBufferPool *pool;
328 pool = *ppool;
331 ff_mutex_lock(&pool->mutex);
332 buffer_pool_flush(pool);
333 ff_mutex_unlock(&pool->mutex);
335 if (atomic_fetch_sub_explicit(&pool->refcount, 1, memory_order_acq_rel) == 1)
336 buffer_pool_free(pool);
342 AVBufferPool *pool = buf->pool;
345 memset(buf->data, FF_MEMORY_POISON, pool->size);
347 ff_mutex_lock(&pool->mutex);
348 buf->next = pool->pool;
349 pool->pool = buf;
350 ff_mutex_unlock(&pool->mutex);
352 if (atomic_fetch_sub_explicit(&pool->refcount, 1, memory_order_acq_rel) == 1)
353 buffer_pool_free(pool);
357 * it is returned to the pool on free */
358 static AVBufferRef *pool_alloc_buffer(AVBufferPool *pool)
363 av_assert0(pool->alloc || pool->alloc2);
365 ret = pool->alloc2 ? pool->alloc2(pool->opaque, pool->size) :
366 pool->alloc(pool->size);
379 buf->pool = pool;
387 AVBufferRef *av_buffer_pool_get(AVBufferPool *pool)
392 ff_mutex_lock(&pool->mutex);
393 buf = pool->pool;
396 ret = buffer_create(&buf->buffer, buf->data, pool->size,
399 pool->pool = buf->next;
404 ret = pool_alloc_buffer(pool);
406 ff_mutex_unlock(&pool->mutex);
409 atomic_fetch_add_explicit(&pool->refcount, 1, memory_order_relaxed);