History

avdevice/alldevices: make avdevice_register_all thread safe

use ff_thread_once

Muhammad Faiz committed 9 years ago

Commit 776f2891 parent af7010a2 files · +9 −8Browse files

Unified · Split

2 files
  1. libavdevice/alldevices.c +9 −7
  2. libavdevice/avdevice.h +0 −1
libavdevice/alldevices.c+9−7
@@ -19,6 +19,7 @@ · 18 unmodified lines
1919 */
2020
2121 #include "config.h"
22+#include "libavutil/thread.h"
2223 #include "avdevice.h"
2324
2425 #define REGISTER_OUTDEV(X, x) \
@@ -37,14 +38,8 @@ · 12 unmodified lines
3738
3839 #define REGISTER_INOUTDEV(X, x) REGISTER_OUTDEV(X, x); REGISTER_INDEV(X, x)
3940
40−void avdevice_register_all(void)
41+static void register_all(void)
4142 {
42− static int initialized;
43−
44− if (initialized)
45− return;
46− initialized = 1;
47−
4843 /* devices */
4944 REGISTER_INOUTDEV(ALSA, alsa);
5045 REGISTER_INDEV (AVFOUNDATION, avfoundation);
@@ -76,3 +71,10 @@ void avdevice_register_all(void) · 25 unmodified lines
7671 REGISTER_INDEV (LIBCDIO, libcdio);
7772 REGISTER_INDEV (LIBDC1394, libdc1394);
7873 }
74+
75+void avdevice_register_all(void)
76+{
77+ AVOnce control = AV_ONCE_INIT;
78+
79+ ff_thread_once(&control, register_all);
80+}
libavdevice/avdevice.h+0−1
@@ -67,7 +67,6 @@ const char *avdevice_license(void); · 66 unmodified lines
6767
6868 /**
6969 * Initialize libavdevice and register all the input and output devices.
70− * @warning This function is not thread safe.
7170 */
7271 void avdevice_register_all(void);
7372

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t