[FFmpeg-cvslog] avfilter/allformats: make av_register_all thread safe

Muhammad Faiz git at videolan.org
Tue Mar 7 15:47:36 EET 2017


ffmpeg | branch: master | Muhammad Faiz <mfcc64 at gmail.com> | Tue Mar  7 15:53:27 2017 +0700| [49635f0a46365f361ce665356bb41e199176021b] | committer: Muhammad Faiz

avfilter/allformats: make av_register_all thread safe

use ff_thread_once

Suggested-by: wm4 <nfxjfg at googlemail.com>
Signed-off-by: Muhammad Faiz <mfcc64 at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=49635f0a46365f361ce665356bb41e199176021b
---

 libavformat/allformats.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 35869e3..132e58b 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -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"
@@ -41,13 +42,8 @@
 
 #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);
 }



More information about the ffmpeg-cvslog mailing list