From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id CACDB47558 for ; Thu, 12 Oct 2023 14:05:01 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E2D5168C99F; Thu, 12 Oct 2023 17:04:58 +0300 (EEST) Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 696AD68C909 for ; Thu, 12 Oct 2023 17:04:52 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 26B31240498 for ; Thu, 12 Oct 2023 16:04:52 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id inJwXQTup8Nt for ; Thu, 12 Oct 2023 16:04:51 +0200 (CEST) Received: from lain.khirnov.net (lain.khirnov.net [IPv6:2001:67c:1138:4306::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "lain.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 6C33A2400FF for ; Thu, 12 Oct 2023 16:04:51 +0200 (CEST) Received: by lain.khirnov.net (Postfix, from userid 1000) id 48AB21601B9; Thu, 12 Oct 2023 16:04:51 +0200 (CEST) From: Anton Khirnov To: FFmpeg development discussions and patches In-Reply-To: References: <169711587240.32606.8092556431828354289@lain.khirnov.net> Mail-Followup-To: FFmpeg development discussions and patches Date: Thu, 12 Oct 2023 16:04:51 +0200 Message-ID: <169711949127.32606.4880530769811767953@lain.khirnov.net> User-Agent: alot/0.8.1 MIME-Version: 1.0 Subject: Re: [FFmpeg-devel] [PATCH 24/42] avcodec/refstruct: Allow to share pools X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Quoting Andreas Rheinhardt (2023-10-12 15:51:18) > Anton Khirnov: > > 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 > >> --- > >> 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? > > > > If I simply incremented the pool's refcount for every entry currently in > use by users, then the entries would only be freed when the last entry > has been returned and all the references to the pool unreferenced. Ok, can you please mention this in a comment somewhere? It's quite non-obvious why do both pool_unref() and refstruct_pool_uninit() exist. > In fact, when I did this, I pondered two things: Shall I make > ff_refstruct_pool_uninit() free all the currently available buffers and > then unreference the caller's reference or shall I just make it a > wrapper to ff_refstruct_unref() to decrement the pool's refcount? The > latter is very simple and I did it; the former could be advantageous in > particular in case of frame-threading in case the dimensions change. (In > this scenario, no user will ever create new entries after the first user > unreferences a pool.) But in other scenarios you might want to get rid of some pool references while still using the others, so maybe that should be a flag if anything. -- Anton Khirnov _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".