diff options
author | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2020-11-27 01:05:25 +0100 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2020-12-04 15:46:46 +0100 |
commit | f41f58f0a74bb7728b2b2a36b9280a827489db48 (patch) | |
tree | ede626671443ab445a793e01a2384f5ee7880ee1 /libavcodec | |
parent | d9b70d64dfb0955783739944db3ce61606338d24 (diff) | |
download | ffmpeg-f41f58f0a74bb7728b2b2a36b9280a827489db48.tar.gz |
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@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/faxcompr.c | 13 |
1 files 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, |