diff mbox series

[FFmpeg-devel,178/191] avcodec/mpeg12: Make initializing VLCs thread-safe

Message ID 20201123193739.1249300-16-andreas.rheinhardt@gmail.com
State New
Headers show
Series VLC, esp. init_vlc patches
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt Nov. 23, 2020, 7:37 p.m. UTC
This automatically makes the eamad, eatqi and mdec init-threadsafe.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/eamad.c  |  1 +
 libavcodec/eatqi.c  |  1 +
 libavcodec/mdec.c   |  1 +
 libavcodec/mpeg12.c | 15 ++++++++-------
 4 files changed, 11 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/eamad.c b/libavcodec/eamad.c
index 7f28abbafe..9dccddd6d3 100644
--- a/libavcodec/eamad.c
+++ b/libavcodec/eamad.c
@@ -349,4 +349,5 @@  AVCodec ff_eamad_decoder = {
     .close          = decode_end,
     .decode         = decode_frame,
     .capabilities   = AV_CODEC_CAP_DR1,
+    .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE,
 };
diff --git a/libavcodec/eatqi.c b/libavcodec/eatqi.c
index 96536b1a08..456bd3c563 100644
--- a/libavcodec/eatqi.c
+++ b/libavcodec/eatqi.c
@@ -189,4 +189,5 @@  AVCodec ff_eatqi_decoder = {
     .close          = tqi_decode_end,
     .decode         = tqi_decode_frame,
     .capabilities   = AV_CODEC_CAP_DR1,
+    .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE,
 };
diff --git a/libavcodec/mdec.c b/libavcodec/mdec.c
index b16cbb6a79..d0bb1162b6 100644
--- a/libavcodec/mdec.c
+++ b/libavcodec/mdec.c
@@ -258,4 +258,5 @@  AVCodec ff_mdec_decoder = {
     .close            = decode_end,
     .decode           = decode_frame,
     .capabilities     = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
+    .caps_internal    = FF_CODEC_CAP_INIT_THREADSAFE,
 };
diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c
index e4f007aec5..e5c611414b 100644
--- a/libavcodec/mpeg12.c
+++ b/libavcodec/mpeg12.c
@@ -30,6 +30,7 @@ 
 #include "libavutil/attributes.h"
 #include "libavutil/avassert.h"
 #include "libavutil/timecode.h"
+#include "libavutil/thread.h"
 
 #include "internal.h"
 #include "avcodec.h"
@@ -134,13 +135,8 @@  VLC ff_mb_ptype_vlc;
 VLC ff_mb_btype_vlc;
 VLC ff_mb_pat_vlc;
 
-av_cold void ff_mpeg12_init_vlcs(void)
+static av_cold void mpeg12_init_vlcs(void)
 {
-    static int done = 0;
-
-    if (!done) {
-        done = 1;
-
         INIT_VLC_STATIC(&ff_dc_lum_vlc, DC_VLC_BITS, 12,
                         ff_mpeg12_vlc_dc_lum_bits, 1, 1,
                         ff_mpeg12_vlc_dc_lum_code, 2, 2, 512);
@@ -168,7 +164,12 @@  av_cold void ff_mpeg12_init_vlcs(void)
 
         INIT_2D_VLC_RL(ff_rl_mpeg1, 680, 0);
         INIT_2D_VLC_RL(ff_rl_mpeg2, 674, 0);
-    }
+}
+
+av_cold void ff_mpeg12_init_vlcs(void)
+{
+    static AVOnce init_static_once = AV_ONCE_INIT;
+    ff_thread_once(&init_static_once, mpeg12_init_vlcs);
 }
 
 /**