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
19 */19 */
20 20
21#include "config.h"21#include "config.h"
22#include "libavutil/thread.h"
22#include "avdevice.h"23#include "avdevice.h"
23 24
24#define REGISTER_OUTDEV(X, x) \25#define REGISTER_OUTDEV(X, x) \
@@ -37,14 +38,8 @@ · 12 unmodified lines
37 38
38#define REGISTER_INOUTDEV(X, x) REGISTER_OUTDEV(X, x); REGISTER_INDEV(X, x)39#define REGISTER_INOUTDEV(X, x) REGISTER_OUTDEV(X, x); REGISTER_INDEV(X, x)
39 40
40void avdevice_register_all(void)41static void register_all(void)
41{42{
42 static int initialized;
43
44 if (initialized)
45 return;
46 initialized = 1;
47
48 /* devices */43 /* devices */
49 REGISTER_INOUTDEV(ALSA, alsa);44 REGISTER_INOUTDEV(ALSA, alsa);
50 REGISTER_INDEV (AVFOUNDATION, avfoundation);45 REGISTER_INDEV (AVFOUNDATION, avfoundation);
@@ -76,3 +71,10 @@ void avdevice_register_all(void) · 25 unmodified lines
76 REGISTER_INDEV (LIBCDIO, libcdio);71 REGISTER_INDEV (LIBCDIO, libcdio);
77 REGISTER_INDEV (LIBDC1394, libdc1394);72 REGISTER_INDEV (LIBDC1394, libdc1394);
78}73}
74
75void 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
67 67
68/**68/**
69 * Initialize libavdevice and register all the input and output devices.69 * Initialize libavdevice and register all the input and output devices.
70 * @warning This function is not thread safe.
71 */70 */
72void avdevice_register_all(void);71void avdevice_register_all(void);
73 72

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