diff options
author | James Almer <jamrial@gmail.com> | 2018-01-04 21:11:31 +0300 |
---|---|---|
committer | James Almer <jamrial@gmail.com> | 2018-01-05 19:18:34 +0300 |
commit | 9ed4ebc530dde681943389b1f97db90b546ad38d (patch) | |
tree | a4661b18ac2cc0ce3121e5fb8268d282c3e92650 /libavcodec/utils.c | |
parent | 7bb1be9af0ea41d6f342655e1d15e30f662fe0f3 (diff) |
avcodec/util: use a mutex instead of atomics in avcodec_register()
Reviewed-by: wm4 <nfxjfg@googlemail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavcodec/utils.c')
-rw-r--r-- | libavcodec/utils.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/libavcodec/utils.c b/libavcodec/utils.c index dfbfe98d63..4d736d2e7d 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" @@ -127,17 +126,24 @@ 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(); + + ff_mutex_lock(&codec_register_mutex); p = last_avcodec; - codec->next = NULL; - while(*p || avpriv_atomic_ptr_cas((void * volatile *)p, NULL, codec)) + while (*p) p = &(*p)->next; + *p = codec; + codec->next = NULL; last_avcodec = &codec->next; + ff_mutex_unlock(&codec_register_mutex); + if (codec->init_static_data) codec->init_static_data(codec); } |