[FFmpeg-cvslog] avdevice/alldevices: make avdevice_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:55:38 2017 +0700| [776f289c0fe82c4e3418a7c504ae3247eb10ffd7] | committer: Muhammad Faiz

avdevice/alldevices: make avdevice_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=776f289c0fe82c4e3418a7c504ae3247eb10ffd7
---

 libavdevice/alldevices.c | 16 +++++++++-------
 libavdevice/avdevice.h   |  1 -
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/libavdevice/alldevices.c b/libavdevice/alldevices.c
index a761be4..75f4ae0 100644
--- a/libavdevice/alldevices.c
+++ b/libavdevice/alldevices.c
@@ -19,6 +19,7 @@
  */
 
 #include "config.h"
+#include "libavutil/thread.h"
 #include "avdevice.h"
 
 #define REGISTER_OUTDEV(X, x)                                           \
@@ -37,14 +38,8 @@
 
 #define REGISTER_INOUTDEV(X, x) REGISTER_OUTDEV(X, x); REGISTER_INDEV(X, x)
 
-void avdevice_register_all(void)
+static void register_all(void)
 {
-    static int initialized;
-
-    if (initialized)
-        return;
-    initialized = 1;
-
     /* devices */
     REGISTER_INOUTDEV(ALSA,             alsa);
     REGISTER_INDEV   (AVFOUNDATION,     avfoundation);
@@ -76,3 +71,10 @@ void avdevice_register_all(void)
     REGISTER_INDEV   (LIBCDIO,          libcdio);
     REGISTER_INDEV   (LIBDC1394,        libdc1394);
 }
+
+void avdevice_register_all(void)
+{
+    AVOnce control = AV_ONCE_INIT;
+
+    ff_thread_once(&control, register_all);
+}
diff --git a/libavdevice/avdevice.h b/libavdevice/avdevice.h
index 6153f2c..84f374a 100644
--- a/libavdevice/avdevice.h
+++ b/libavdevice/avdevice.h
@@ -67,7 +67,6 @@ const char *avdevice_license(void);
 
 /**
  * Initialize libavdevice and register all the input and output devices.
- * @warning This function is not thread safe.
  */
 void avdevice_register_all(void);
 



More information about the ffmpeg-cvslog mailing list