[FFmpeg-devel] [PATCH 4/4] avdevice/alldevice: make avdevice_register_all thread safe
Muhammad Faiz
mfcc64 at gmail.com
Mon Mar 6 21:47:39 EET 2017
Signed-off-by: Muhammad Faiz <mfcc64 at gmail.com>
---
libavdevice/alldevices.c | 13 ++++++++++---
libavdevice/avdevice.h | 1 -
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/libavdevice/alldevices.c b/libavdevice/alldevices.c
index a761be4..cc8b8ce 100644
--- a/libavdevice/alldevices.c
+++ b/libavdevice/alldevices.c
@@ -18,6 +18,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include <stdatomic.h>
+
#include "config.h"
#include "avdevice.h"
@@ -39,11 +41,14 @@
void avdevice_register_all(void)
{
- static int initialized;
+ static atomic_int initialized;
+ static atomic_int ready;
- if (initialized)
+ if (atomic_exchange_explicit(&initialized, 1, memory_order_relaxed)) {
+ while (!atomic_load_explicit(&ready, memory_order_relaxed))
+ ;
return;
- initialized = 1;
+ }
/* devices */
REGISTER_INOUTDEV(ALSA, alsa);
@@ -75,4 +80,6 @@ void avdevice_register_all(void)
/* external libraries */
REGISTER_INDEV (LIBCDIO, libcdio);
REGISTER_INDEV (LIBDC1394, libdc1394);
+
+ atomic_store_explicit(&ready, 1, memory_order_relaxed);
}
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);
--
2.9.3
More information about the ffmpeg-devel
mailing list