[FFmpeg-cvslog] avcodec/faxcompr: Make ff_ccitt_unpack_init() thread-safe

Andreas Rheinhardt git at videolan.org
Fri Dec 4 17:41:01 EET 2020


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at gmail.com> | Fri Nov 27 01:05:25 2020 +0100| [f41f58f0a74bb7728b2b2a36b9280a827489db48] | committer: Andreas Rheinhardt

avcodec/faxcompr: Make ff_ccitt_unpack_init() thread-safe

This will allow to make the TIFF decoder's init function thread-safe.

Reviewed-by: Anton Khirnov <anton at khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f41f58f0a74bb7728b2b2a36b9280a827489db48
---

 libavcodec/faxcompr.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

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,



More information about the ffmpeg-cvslog mailing list