[FFmpeg-devel] [PATCH 3/7] avcodec/parser: convert to stdatomic
James Almer
jamrial at gmail.com
Thu Mar 23 01:34:08 EET 2017
Signed-off-by: James Almer <jamrial at gmail.com>
---
libavcodec/parser.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/libavcodec/parser.c b/libavcodec/parser.c
index 30cfc55cbc..831927e5a7 100644
--- a/libavcodec/parser.c
+++ b/libavcodec/parser.c
@@ -21,10 +21,10 @@
*/
#include <stdint.h>
+#include <stdatomic.h>
#include <string.h>
#include "libavutil/avassert.h"
-#include "libavutil/atomic.h"
#include "libavutil/internal.h"
#include "libavutil/mem.h"
@@ -32,6 +32,7 @@
#include "parser.h"
static AVCodecParser *av_first_parser = NULL;
+static AVCodecParser **last_parser = &av_first_parser;
AVCodecParser *av_parser_next(const AVCodecParser *p)
{
@@ -43,9 +44,14 @@ AVCodecParser *av_parser_next(const AVCodecParser *p)
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));
+ AVCodecParser **f = last_parser;
+ const AVCodecParser *cmp = NULL;
+
+ parser->next = NULL;
+
+ while(*f || !atomic_compare_exchange_strong(f, &cmp, parser))
+ f = &(*f)->next;
+ last_parser = &parser->next;
}
AVCodecParserContext *av_parser_init(int codec_id)
--
2.12.0
More information about the ffmpeg-devel
mailing list