[FFmpeg-devel,3/7] avcodec/parser: convert to stdatomic

Submitted by James Almer on March 22, 2017, 11:34 p.m.

Details

Message ID 20170322233412.6952-4-jamrial@gmail.com
State New
Headers show

Commit Message

James Almer March 22, 2017, 11:34 p.m.
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/parser.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

Patch hide | download patch | download mbox

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)