Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/libavcodec/parser.c b/libavcodec/parser.c
- index 670680ea7c..747ea2ee8a 100644
- --- a/libavcodec/parser.c
- +++ b/libavcodec/parser.c
- @@ -25,9 +25,9 @@
- #include <string.h>
- #include "libavutil/avassert.h"
- -#include "libavutil/atomic.h"
- #include "libavutil/internal.h"
- #include "libavutil/mem.h"
- +#include "libavutil/thread.h"
- #include "internal.h"
- #include "parser.h"
- @@ -42,11 +42,14 @@ AVCodecParser *av_parser_next(const AVCodecParser *p)
- return av_first_parser;
- }
- +static AVMutex parser_register_mutex = AV_MUTEX_INITIALIZER;
- +
- void av_register_codec_parser(AVCodecParser *parser)
- {
- - do {
- - parser->next = av_first_parser;
- - } while (parser->next != avpriv_atomic_ptr_cas((void * volatile *)&av_first_parser, parser->next, parser));
- + ff_mutex_lock(&parser_register_mutex);
- + parser->next = av_first_parser;
- + av_first_parser = parser;
- + ff_mutex_unlock(&parser_register_mutex);
- }
- AVCodecParserContext *av_parser_init(int codec_id)
- diff --git a/libavcodec/utils.c b/libavcodec/utils.c
- index dfbfe98d63..58216b984a 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,19 @@ 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;
- -
- - while(*p || avpriv_atomic_ptr_cas((void * volatile *)p, NULL, codec))
- + ff_mutex_lock(&codec_register_mutex);
- + p = &first_avcodec;
- + while (*p)
- p = &(*p)->next;
- - last_avcodec = &codec->next;
- + *p = codec;
- + codec->next = NULL;
- + ff_mutex_unlock(&codec_register_mutex);
- if (codec->init_static_data)
- codec->init_static_data(codec);
- diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
- index b98b32bacb..0c1a5b6488 100644
- --- a/libavfilter/avfilter.c
- +++ b/libavfilter/avfilter.c
- @@ -19,7 +19,6 @@
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
- -#include "libavutil/atomic.h"
- #include "libavutil/avassert.h"
- #include "libavutil/avstring.h"
- #include "libavutil/buffer.h"
- @@ -33,6 +32,7 @@
- #include "libavutil/pixdesc.h"
- #include "libavutil/rational.h"
- #include "libavutil/samplefmt.h"
- +#include "libavutil/thread.h"
- #define FF_INTERNAL_FIELDS 1
- #include "framequeue.h"
- @@ -574,7 +574,6 @@ int avfilter_process_command(AVFilterContext *filter, const char *cmd, const cha
- }
- static AVFilter *first_filter;
- -static AVFilter **last_filter = &first_filter;
- const AVFilter *avfilter_get_by_name(const char *name)
- {
- @@ -590,18 +589,23 @@ const AVFilter *avfilter_get_by_name(const char *name)
- return NULL;
- }
- +static AVMutex filter_register_mutex = AV_MUTEX_INITIALIZER;
- +
- int avfilter_register(AVFilter *filter)
- {
- - AVFilter **f = last_filter;
- + AVFilter **f;
- /* the filter must select generic or internal exclusively */
- av_assert0((filter->flags & AVFILTER_FLAG_SUPPORT_TIMELINE) != AVFILTER_FLAG_SUPPORT_TIMELINE);
- - filter->next = NULL;
- + ff_mutex_lock(&filter_register_mutex);
- + f = &first_filter;
- - while(*f || avpriv_atomic_ptr_cas((void * volatile *)f, NULL, filter))
- + while (*f)
- f = &(*f)->next;
- - last_filter = &filter->next;
- + *f = filter;
- + filter->next = NULL;
- + ff_mutex_unlock(&filter_register_mutex);
- return 0;
- }
- diff --git a/libavformat/format.c b/libavformat/format.c
- index 38ca2a3465..ad37923e25 100644
- --- a/libavformat/format.c
- +++ b/libavformat/format.c
- @@ -19,10 +19,10 @@
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
- -#include "libavutil/atomic.h"
- #include "libavutil/avstring.h"
- #include "libavutil/bprint.h"
- #include "libavutil/opt.h"
- +#include "libavutil/thread.h"
- #include "avio_internal.h"
- #include "avformat.h"
- @@ -39,9 +39,6 @@ static AVInputFormat *first_iformat = NULL;
- /** head of registered output format linked list */
- static AVOutputFormat *first_oformat = NULL;
- -static AVInputFormat **last_iformat = &first_iformat;
- -static AVOutputFormat **last_oformat = &first_oformat;
- -
- AVInputFormat *av_iformat_next(const AVInputFormat *f)
- {
- if (f)
- @@ -58,28 +55,35 @@ AVOutputFormat *av_oformat_next(const AVOutputFormat *f)
- return first_oformat;
- }
- +static AVMutex iformat_register_mutex = AV_MUTEX_INITIALIZER;
- +
- void av_register_input_format(AVInputFormat *format)
- {
- - AVInputFormat **p = last_iformat;
- + AVInputFormat **p;
- + ff_mutex_lock(&iformat_register_mutex);
- + p = &first_iformat;
- - // Note, format could be added after the first 2 checks but that implies that *p is no longer NULL
- - while(p != &format->next && !format->next && avpriv_atomic_ptr_cas((void * volatile *)p, NULL, format))
- + while (*p)
- p = &(*p)->next;
- - if (!format->next)
- - last_iformat = &format->next;
- + *p = format;
- + format->next = NULL;
- + ff_mutex_unlock(&iformat_register_mutex);
- }
- +static AVMutex oformat_register_mutex = AV_MUTEX_INITIALIZER;
- +
- void av_register_output_format(AVOutputFormat *format)
- {
- - AVOutputFormat **p = last_oformat;
- + AVOutputFormat **p = &first_oformat;
- - // Note, format could be added after the first 2 checks but that implies that *p is no longer NULL
- - while(p != &format->next && !format->next && avpriv_atomic_ptr_cas((void * volatile *)p, NULL, format))
- + ff_mutex_lock(&oformat_register_mutex);
- + while (*p)
- p = &(*p)->next;
- - if (!format->next)
- - last_oformat = &format->next;
- + *p = format;
- + format->next = NULL;
- + ff_mutex_unlock(&oformat_register_mutex);
- }
- int av_match_ext(const char *filename, const char *extensions)
Advertisement
Add Comment
Please, Sign In to add comment