On Thu, Jan 04, 2018 at 03:19:01PM -0300, James Almer wrote: > Signed-off-by: James Almer <jamr...@gmail.com> > --- > libavcodec/utils.c | 15 +++++++++------ > 1 file changed, 9 insertions(+), 6 deletions(-) > > diff --git a/libavcodec/utils.c b/libavcodec/utils.c > index dfbfe98d63..61acf36c4b 100644 > --- a/libavcodec/utils.c > +++ b/libavcodec/utils.c > @@ -26,7 +26,6 @@ > */ > > #include "config.h" > -#include "libavutil/atomic.h" > #include "libavutil/attributes.h" > #include "libavutil/avassert.h" > #include "libavutil/avstring.h" > @@ -95,7 +94,6 @@ void av_fast_padded_mallocz(void *ptr, unsigned int *size, > size_t min_size) > > /* encoder management */ > static AVCodec *first_avcodec = NULL; > -static AVCodec **last_avcodec = &first_avcodec; > > AVCodec *av_codec_next(const AVCodec *c) > { > @@ -127,16 +125,21 @@ int av_codec_is_decoder(const AVCodec *codec) > return codec && (codec->decode || codec->receive_frame); > } > > +static AVMutex codec_register_mutex = AV_MUTEX_INITIALIZER; > + > av_cold void avcodec_register(AVCodec *codec) > { > AVCodec **p; > avcodec_init(); > - p = last_avcodec; > - codec->next = NULL; > + ff_mutex_lock(&codec_register_mutex); > + p = &first_avcodec; > > - while(*p || avpriv_atomic_ptr_cas((void * volatile *)p, NULL, codec)) > + while (*p) > p = &(*p)->next; > - last_avcodec = &codec->next; > + *p = codec; > + codec->next = NULL; > + > + ff_mutex_unlock(&codec_register_mutex);
the code should keep track of the last entry of the list as previously and not search through the list each time for the end, especially not under a mutex this is not as negligible fast as you may think adding 1000 entries to a list like this will need ~ half millon iterations [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Concerning the gods, I have no means of knowing whether they exist or not or of what sort they may be, because of the obscurity of the subject, and the brevity of human life -- Protagoras
signature.asc
Description: PGP signature
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel