avcodec/allcodecs: make avcodec_register_all thread safe
authorMuhammad Faiz <mfcc64@gmail.com>
Tue, 7 Mar 2017 08:51:12 +0000 (15:51 +0700)
committerMuhammad Faiz <mfcc64@gmail.com>
Tue, 7 Mar 2017 13:34:44 +0000 (20:34 +0700)
use ff_thread_once

Suggested-by: wm4 <nfxjfg@googlemail.com>
Signed-off-by: Muhammad Faiz <mfcc64@gmail.com>
libavcodec/allcodecs.c

index a265ce5..074efd4 100644 (file)
@@ -25,6 +25,7 @@
  */
 
 #include "config.h"
+#include "libavutil/thread.h"
 #include "avcodec.h"
 #include "version.h"
 
             av_register_codec_parser(&ff_##x##_parser);                 \
     }
 
-void avcodec_register_all(void)
+static void register_all(void)
 {
-    static int initialized;
-
-    if (initialized)
-        return;
-    initialized = 1;
-
     /* hardware accelerators */
     REGISTER_HWACCEL(H263_VAAPI,        h263_vaapi);
     REGISTER_HWACCEL(H263_VIDEOTOOLBOX, h263_videotoolbox);
@@ -718,3 +713,10 @@ void avcodec_register_all(void)
     REGISTER_PARSER(VP9,                vp9);
     REGISTER_PARSER(XMA,                xma);
 }
+
+void avcodec_register_all(void)
+{
+    static AVOnce control = AV_ONCE_INIT;
+
+    ff_thread_once(&control, register_all);
+}