diff mbox series

[FFmpeg-devel,v2,030/162] avcodec/rv10: Make initializing static RV10 VLCs thread-safe

Message ID 20201120072116.818090-31-andreas.rheinhardt@gmail.com
State Accepted
Commit e9d06fef62d811828cf49c4d0c383ddacc22884d
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. 20, 2020, 7:19 a.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/rv10.c | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

Comments

Moritz Barsnick Nov. 24, 2020, 10:30 p.m. UTC | #1
On Fri, Nov 20, 2020 at 08:19:03 +0100, Andreas Rheinhardt wrote:
> +static av_cold void rv10_init_static(void)
> +{
> +        INIT_VLC_STATIC(&rv_dc_lum, DC_VLC_BITS, 256,
> +                        rv_lum_bits, 1, 1,
> +                        rv_lum_code, 2, 2, 16384);
> +        INIT_VLC_STATIC(&rv_dc_chrom, DC_VLC_BITS, 256,
> +                        rv_chrom_bits, 1, 1,
> +                        rv_chrom_code, 2, 2, 16388);
> +    ff_h263_decode_init_vlc();
> +}

Nit: indentation.

Moritz
Andreas Rheinhardt Nov. 24, 2020, 11:28 p.m. UTC | #2
Moritz Barsnick:
> On Fri, Nov 20, 2020 at 08:19:03 +0100, Andreas Rheinhardt wrote:
>> +static av_cold void rv10_init_static(void)
>> +{
>> +        INIT_VLC_STATIC(&rv_dc_lum, DC_VLC_BITS, 256,
>> +                        rv_lum_bits, 1, 1,
>> +                        rv_lum_code, 2, 2, 16384);
>> +        INIT_VLC_STATIC(&rv_dc_chrom, DC_VLC_BITS, 256,
>> +                        rv_chrom_bits, 1, 1,
>> +                        rv_chrom_code, 2, 2, 16388);
>> +    ff_h263_decode_init_vlc();
>> +}
> 
> Nit: indentation.
> 
> Moritz

This has been intentionally not done in this patch to show that this
code has just been moved and not really modified; the proper indentation
will be restored in the next patch (which replaces these two macros with
other macros).

- Andreas
diff mbox series

Patch

diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c
index e594160fea..3a487a6b3e 100644
--- a/libavcodec/rv10.c
+++ b/libavcodec/rv10.c
@@ -28,6 +28,7 @@ 
 #include <inttypes.h>
 
 #include "libavutil/imgutils.h"
+#include "libavutil/thread.h"
 
 #include "avcodec.h"
 #include "error_resilience.h"
@@ -463,11 +464,22 @@  static int rv20_decode_picture_header(RVDecContext *rv)
     return s->mb_width * s->mb_height - mb_pos;
 }
 
+static av_cold void rv10_init_static(void)
+{
+        INIT_VLC_STATIC(&rv_dc_lum, DC_VLC_BITS, 256,
+                        rv_lum_bits, 1, 1,
+                        rv_lum_code, 2, 2, 16384);
+        INIT_VLC_STATIC(&rv_dc_chrom, DC_VLC_BITS, 256,
+                        rv_chrom_bits, 1, 1,
+                        rv_chrom_code, 2, 2, 16388);
+    ff_h263_decode_init_vlc();
+}
+
 static av_cold int rv10_decode_init(AVCodecContext *avctx)
 {
+    static AVOnce init_static_once = AV_ONCE_INIT;
     RVDecContext *rv = avctx->priv_data;
     MpegEncContext *s = &rv->m;
-    static int done = 0;
     int major_ver, minor_ver, micro_ver, ret;
 
     if (avctx->extradata_size < 8) {
@@ -525,18 +537,9 @@  static av_cold int rv10_decode_init(AVCodecContext *avctx)
         return ret;
 
     ff_h263dsp_init(&s->h263dsp);
-    ff_h263_decode_init_vlc();
 
-    /* init rv vlc */
-    if (!done) {
-        INIT_VLC_STATIC(&rv_dc_lum, DC_VLC_BITS, 256,
-                        rv_lum_bits, 1, 1,
-                        rv_lum_code, 2, 2, 16384);
-        INIT_VLC_STATIC(&rv_dc_chrom, DC_VLC_BITS, 256,
-                        rv_chrom_bits, 1, 1,
-                        rv_chrom_code, 2, 2, 16388);
-        done = 1;
-    }
+    /* init static VLCs */
+    ff_thread_once(&init_static_once, rv10_init_static);
 
     return 0;
 }