diff mbox series

[FFmpeg-devel,v2,057/162] avcodec/mpegaudiodsp: Make ff_mpadsp_init() thread-safe

Message ID 20201120072116.818090-58-andreas.rheinhardt@gmail.com
State Accepted
Commit ead313415037bbb94954a346a17796c0f741f790
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
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt Nov. 20, 2020, 7:19 a.m. UTC
The only thing missing for this is to make ff_mpadsp_init_x86()
thread-safe; it currently isn't because a static table is initialized
every time ff_mpadsp_init() is called (when ARCH_X86 is true). Solve
this by initializing this table only once, namely together with the
ordinary not-arch specific tables. This also allows to reuse their AVOnce.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
This is needed for Musepack 7 and 8 as well as qdm2 and the MPEG audio
decoders.

 libavcodec/mpegaudiodsp.c     | 3 +++
 libavcodec/mpegaudiodsp.h     | 1 +
 libavcodec/x86/mpegaudiodsp.c | 9 ++++++---
 3 files changed, 10 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/mpegaudiodsp.c b/libavcodec/mpegaudiodsp.c
index 0a14ff549e..f03e244644 100644
--- a/libavcodec/mpegaudiodsp.c
+++ b/libavcodec/mpegaudiodsp.c
@@ -73,6 +73,9 @@  static av_cold void mpadsp_init_tabs(void)
             ff_mdct_win_fixed[j + 4][i + 1] = -ff_mdct_win_fixed[j][i + 1];
         }
     }
+
+    if (ARCH_X86)
+        ff_mpadsp_init_x86_tabs();
 }
 
 av_cold void ff_mpadsp_init(MPADSPContext *s)
diff --git a/libavcodec/mpegaudiodsp.h b/libavcodec/mpegaudiodsp.h
index 28dcec576c..4c9b05ebac 100644
--- a/libavcodec/mpegaudiodsp.h
+++ b/libavcodec/mpegaudiodsp.h
@@ -63,6 +63,7 @@  void ff_mpadsp_init_aarch64(MPADSPContext *s);
 void ff_mpadsp_init_arm(MPADSPContext *s);
 void ff_mpadsp_init_ppc(MPADSPContext *s);
 void ff_mpadsp_init_x86(MPADSPContext *s);
+void ff_mpadsp_init_x86_tabs(void);
 void ff_mpadsp_init_mipsfpu(MPADSPContext *s);
 void ff_mpadsp_init_mipsdsp(MPADSPContext *s);
 
diff --git a/libavcodec/x86/mpegaudiodsp.c b/libavcodec/x86/mpegaudiodsp.c
index f46a5c4f3d..d646c6dbcb 100644
--- a/libavcodec/x86/mpegaudiodsp.c
+++ b/libavcodec/x86/mpegaudiodsp.c
@@ -239,10 +239,8 @@  DECL_IMDCT_BLOCKS(avx,avx)
 #endif
 #endif /* HAVE_X86ASM */
 
-av_cold void ff_mpadsp_init_x86(MPADSPContext *s)
+av_cold void ff_mpadsp_init_x86_tabs(void)
 {
-    av_unused int cpu_flags = av_get_cpu_flags();
-
     int i, j;
     for (j = 0; j < 4; j++) {
         for (i = 0; i < 40; i ++) {
@@ -256,6 +254,11 @@  av_cold void ff_mpadsp_init_x86(MPADSPContext *s)
             mdct_win_sse[1][j][4*i + 3] = ff_mdct_win_float[j + 4][i];
         }
     }
+}
+
+av_cold void ff_mpadsp_init_x86(MPADSPContext *s)
+{
+    av_unused int cpu_flags = av_get_cpu_flags();
 
 #if HAVE_6REGS && HAVE_SSE_INLINE
     if (INLINE_SSE(cpu_flags)) {