diff mbox series

[FFmpeg-devel,163/191] avcodec/atrac: Make generating tables thread-safe

Message ID 20201123193739.1249300-1-andreas.rheinhardt@gmail.com
State Accepted
Commit 94a55f28aa2cd0c5afb5ee621cfcca746781079c
Headers show
Series VLC, esp. init_vlc patches | expand

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
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/atrac.c | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/atrac.c b/libavcodec/atrac.c
index 12e8997dbc..bf9878be45 100644
--- a/libavcodec/atrac.c
+++ b/libavcodec/atrac.c
@@ -30,6 +30,8 @@ 
 #include <stdio.h>
 #include <string.h>
 
+#include "libavutil/thread.h"
+
 #include "avcodec.h"
 #include "atrac.h"
 
@@ -45,22 +47,23 @@  static const float qmf_48tap_half[24] = {
    -0.043596379,   -0.099384367,   0.13207909,    0.46424159
 };
 
-av_cold void ff_atrac_generate_tables(void)
+static av_cold void atrac_generate_tables(void)
 {
-    int i;
-    float s;
-
     /* Generate scale factors */
-    if (!ff_atrac_sf_table[63])
-        for (i=0 ; i<64 ; i++)
-            ff_atrac_sf_table[i] = pow(2.0, (i - 15) / 3.0);
+    for (int i = 0; i < 64; i++)
+        ff_atrac_sf_table[i] = pow(2.0, (i - 15) / 3.0);
 
     /* Generate the QMF window. */
-    if (!qmf_window[47])
-        for (i=0 ; i<24; i++) {
-            s = qmf_48tap_half[i] * 2.0;
-            qmf_window[i] = qmf_window[47 - i] = s;
-        }
+    for (int i = 0; i < 24; i++) {
+        float s = qmf_48tap_half[i] * 2.0;
+        qmf_window[i] = qmf_window[47 - i] = s;
+    }
+}
+
+av_cold void ff_atrac_generate_tables(void)
+{
+    static AVOnce init_static_once = AV_ONCE_INIT;
+    ff_thread_once(&init_static_once, atrac_generate_tables);
 }
 
 av_cold void ff_atrac_init_gain_compensation(AtracGCContext *gctx, int id2exp_offset,