diff mbox series

[FFmpeg-devel,43/45] avcodec/faxcompr: Make ff_ccitt_unpack_init() thread-safe

Message ID 20201127010249.2724610-43-andreas.rheinhardt@gmail.com
State Accepted
Commit f41f58f0a74bb7728b2b2a36b9280a827489db48
Headers show
Series [FFmpeg-devel,01/45] avcodec/a64multienc: Fix memleak upon init failure
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. 27, 2020, 1:02 a.m. UTC
This will allow to make the TIFF decoder's init function thread-safe.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/faxcompr.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

Comments

Anton Khirnov Dec. 4, 2020, 12:10 p.m. UTC | #1
Quoting Andreas Rheinhardt (2020-11-27 02:02:47)
> This will allow to make the TIFF decoder's init function thread-safe.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavcodec/faxcompr.c | 13 ++++++++-----
>  1 file changed, 8 insertions(+), 5 deletions(-)
> 

Looks ok
diff mbox series

Patch

diff --git a/libavcodec/faxcompr.c b/libavcodec/faxcompr.c
index 2a1d2bc3f6..3dd64cf730 100644
--- a/libavcodec/faxcompr.c
+++ b/libavcodec/faxcompr.c
@@ -24,6 +24,7 @@ 
  * CCITT Fax Group 3 and 4 decompression
  * @author Konstantin Shishkov
  */
+#include "libavutil/thread.h"
 #include "avcodec.h"
 #include "get_bits.h"
 #include "put_bits.h"
@@ -96,15 +97,12 @@  static const uint8_t ccitt_group3_2d_lens[11] = {
 
 static VLC ccitt_vlc[2], ccitt_group3_2d_vlc;
 
-av_cold void ff_ccitt_unpack_init(void)
+static av_cold void ccitt_unpack_init(void)
 {
     static VLC_TYPE code_table1[528][2];
     static VLC_TYPE code_table2[648][2];
     int i;
-    static int initialized = 0;
 
-    if (initialized)
-        return;
     ccitt_vlc[0].table = code_table1;
     ccitt_vlc[0].table_allocated = 528;
     ccitt_vlc[1].table = code_table2;
@@ -119,7 +117,12 @@  av_cold void ff_ccitt_unpack_init(void)
     INIT_VLC_STATIC(&ccitt_group3_2d_vlc, 9, 11,
                     ccitt_group3_2d_lens, 1, 1,
                     ccitt_group3_2d_bits, 1, 1, 512);
-    initialized = 1;
+}
+
+av_cold void ff_ccitt_unpack_init(void)
+{
+    static AVOnce init_static_once = AV_ONCE_INIT;
+    ff_thread_once(&init_static_once, ccitt_unpack_init);
 }
 
 static int decode_uncompressed(AVCodecContext *avctx, GetBitContext *gb,