avformat: make av_register_*put_format() thread safe
authorMichael Niedermayer <michaelni@gmx.at>
Sat, 29 Jun 2013 01:44:15 +0000 (03:44 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Sat, 29 Jun 2013 01:46:10 +0000 (03:46 +0200)
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
libavformat/format.c

index c1be85983ae8ff6314edcbe432b603a2fbc581ba..ac9100b6045d383faf809506ca54586103385e41 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "avformat.h"
 #include "internal.h"
 
 #include "avformat.h"
 #include "internal.h"
+#include "libavutil/atomic.h"
 #include "libavutil/avstring.h"
 
 /**
 #include "libavutil/avstring.h"
 
 /**
@@ -52,22 +53,18 @@ void av_register_input_format(AVInputFormat *format)
 {
     AVInputFormat **p = &first_iformat;
 
 {
     AVInputFormat **p = &first_iformat;
 
-    while (*p != NULL)
-        p = &(*p)->next;
-
-    *p = format;
     format->next = NULL;
     format->next = NULL;
+    while(avpriv_atomic_ptr_cas((void * volatile *)p, NULL, format))
+        p = &(*p)->next;
 }
 
 void av_register_output_format(AVOutputFormat *format)
 {
     AVOutputFormat **p = &first_oformat;
 
 }
 
 void av_register_output_format(AVOutputFormat *format)
 {
     AVOutputFormat **p = &first_oformat;
 
-    while (*p != NULL)
-        p = &(*p)->next;
-
-    *p = format;
     format->next = NULL;
     format->next = NULL;
+    while(avpriv_atomic_ptr_cas((void * volatile *)p, NULL, format))
+        p = &(*p)->next;
 }
 
 int av_match_ext(const char *filename, const char *extensions)
 }
 
 int av_match_ext(const char *filename, const char *extensions)