[FFmpeg-devel] [PATCH 24/42] avcodec/refstruct: Allow to share pools
Anton Khirnov
anton at khirnov.net
Thu Oct 12 16:04:32 EEST 2023
Quoting Andreas Rheinhardt (2023-09-19 21:57:16)
> To do this, make FFRefStructPool itself refcounted according
> to the RefStruct API.
>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
> ---
> libavcodec/refstruct.c | 29 ++++++++++++++++-------------
> libavcodec/refstruct.h | 5 ++++-
> 2 files changed, 20 insertions(+), 14 deletions(-)
>
> diff --git a/libavcodec/refstruct.c b/libavcodec/refstruct.c
> index f8d040874d..2108ff8163 100644
> --- a/libavcodec/refstruct.c
> +++ b/libavcodec/refstruct.c
> @@ -187,7 +187,7 @@ static void pool_free(FFRefStructPool *pool)
> pthread_mutex_destroy(&pool->mutex);
> if (pool->free_cb)
> pool->free_cb(pool->opaque);
> - av_free(pool);
> + av_free(get_refcount(pool));
> }
>
> static void pool_free_entry(FFRefStructPool *pool, RefCount *ref)
> @@ -278,13 +278,17 @@ void *ff_refstruct_pool_get(FFRefStructPool *pool)
> return ret;
> }
>
> -void ff_refstruct_pool_uninit(FFRefStructPool **poolp)
> +static void pool_unref(void *ref)
> {
> - FFRefStructPool *pool = *poolp;
> - RefCount *entry;
> + FFRefStructPool *pool = get_userdata(ref);
> + if (atomic_fetch_sub_explicit(&pool->refcount, 1, memory_order_acq_rel) == 1)
Is there a reason you cannot fold pool->refcount into the pool's
containing RefStruct?
--
Anton Khirnov
More information about the ffmpeg-devel
mailing list