Skip to content

Commit

Permalink
avdevice/alldevices: make avdevice_register_all thread safe
Browse files Browse the repository at this point in the history
use ff_thread_once

Suggested-by: wm4 <[email protected]>
Signed-off-by: Muhammad Faiz <[email protected]>
  • Loading branch information
mfcc64 committed Mar 7, 2017
1 parent af7010a commit 776f289
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
16 changes: 9 additions & 7 deletions libavdevice/alldevices.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/

#include "config.h"
#include "libavutil/thread.h"
#include "avdevice.h"

#define REGISTER_OUTDEV(X, x) \
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
1 change: 0 additions & 1 deletion libavdevice/avdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 776f289

Please sign in to comment.