avfilter/allformats: make av_register_all thread safe
authorMuhammad Faiz <mfcc64@gmail.com>
Tue, 7 Mar 2017 08:53:27 +0000 (15:53 +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>
libavformat/allformats.c

index 35869e3..132e58b 100644 (file)
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/thread.h"
 #include "avformat.h"
 #include "rtp.h"
 #include "rdt.h"
 
 #define REGISTER_MUXDEMUX(X, x) REGISTER_MUXER(X, x); REGISTER_DEMUXER(X, x)
 
-void av_register_all(void)
+static void register_all(void)
 {
-    static int initialized;
-
-    if (initialized)
-        return;
-
     avcodec_register_all();
 
     /* (de)muxers */
@@ -383,6 +379,11 @@ void av_register_all(void)
     REGISTER_DEMUXER (LIBMODPLUG,       libmodplug);
     REGISTER_MUXDEMUX(LIBNUT,           libnut);
     REGISTER_DEMUXER (LIBOPENMPT,       libopenmpt);
+}
+
+void av_register_all(void)
+{
+    AVOnce control = AV_ONCE_INIT;
 
-    initialized = 1;
+    ff_thread_once(&control, register_all);
 }