On Tue, Sep 19, 2023 at 09:57:09PM +0200, Andreas Rheinhardt wrote: > Very similar to the AVBufferPool API, but with some differences: > 1. Reusing an already existing entry does not incur an allocation > at all any more (the AVBufferPool API needs to allocate an AVBufferRef). > 2. The tasks done while holding the lock are smaller; e.g. > allocating new entries is now performed without holding the lock. > The same goes for freeing. > 3. The entries are freed as soon as possible (the AVBufferPool API > frees them in two batches: The first in av_buffer_pool_uninit() and > the second immediately before the pool is freed when the last > outstanding entry is returned to the pool). > 4. The API is designed for objects and not naked buffers and > therefore has a reset callback. This is called whenever an object > is returned to the pool. > 5. Just like with the RefStruct API, custom allocators are not > supported. > > (If desired, the FFRefStructPool struct itself could be made > reference counted via the RefStruct API; an FFRefStructPool > would then be freed via ff_refstruct_unref().) > > Signed-off-by: Andreas Rheinhardt > --- > libavcodec/refstruct.c | 194 ++++++++++++++++++++++++++++++++++++++++- > libavcodec/refstruct.h | 128 +++++++++++++++++++++++++++ > 2 files changed, 321 insertions(+), 1 deletion(-) seems to break building on ppc (--disable-pthreads) CC libavcodec/refstruct.o src/libavcodec/refstruct.c: In function ‘pool_free’: src/libavcodec/refstruct.c:187:5: error: implicit declaration of function ‘pthread_mutex_destroy’; did you mean ‘ff_mutex_destroy’? [-Werror=implicit-function-declaration] pthread_mutex_destroy(&pool->mutex); ^~~~~~~~~~~~~~~~~~~~~ ff_mutex_destroy src/libavcodec/refstruct.c: In function ‘pool_return_entry’: src/libavcodec/refstruct.c:205:5: error: implicit declaration of function ‘pthread_mutex_lock’; did you mean ‘ff_mutex_lock’? [-Werror=implicit-function-declaration] pthread_mutex_lock(&pool->mutex); ^~~~~~~~~~~~~~~~~~ ff_mutex_lock src/libavcodec/refstruct.c:211:5: error: implicit declaration of function ‘pthread_mutex_unlock’; did you mean ‘ff_mutex_unlock’? [-Werror=implicit-function-declaration] pthread_mutex_unlock(&pool->mutex); ^~~~~~~~~~~~~~~~~~~~ ff_mutex_unlock src/libavcodec/refstruct.c: In function ‘ff_refstruct_pool_alloc_ext_c’: src/libavcodec/refstruct.c:339:11: error: implicit declaration of function ‘pthread_mutex_init’; did you mean ‘ff_mutex_init’? [-Werror=implicit-function-declaration] err = pthread_mutex_init(&pool->mutex, NULL); ^~~~~~~~~~~~~~~~~~ ff_mutex_init cc1: some warnings being treated as errors /home/michael/ffmpeg-git/ffmpeg/ffbuild/common.mak:81: recipe for target 'libavcodec/refstruct.o' failed make: *** [libavcodec/refstruct.o] Error 1 make: Target 'all' not remade because of errors. [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB During times of universal deceit, telling the truth becomes a revolutionary act. -- George Orwell