summaryrefslogtreecommitdiff
path: root/libavcodec/jpeg2000.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-05-07 04:49:27 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-05-12 06:00:14 +0200
commit3c26773ae28ebd6a549491d432a6990450b068cf (patch)
treef1993c04a8d762de1b9aa80e95dea41cb6df7eac /libavcodec/jpeg2000.c
parentb43e946b71e144a4ce5e83cd18e5a07155edb26f (diff)
avcodec/jpeg2000dec: Make decoder init-threadsafe
The JPEG-2000 decoder and encoder share common luts; the decoder initializes them once, guarded by a dedicated AVOnce, whereas the encoder initializes them always during init. This means that the decoder is not init-threadsafe; in fact there is a potential data race because these luts can be initialized while an active decoder/encoder is using them. Fix this and make the decoder init-threadsafe by making the initialization function guard initialization itself with a dedicated AVOnce. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavcodec/jpeg2000.c')
-rw-r--r--libavcodec/jpeg2000.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/libavcodec/jpeg2000.c b/libavcodec/jpeg2000.c
index 56d98c8a89..324908d833 100644
--- a/libavcodec/jpeg2000.c
+++ b/libavcodec/jpeg2000.c
@@ -30,6 +30,7 @@
#include "libavutil/common.h"
#include "libavutil/imgutils.h"
#include "libavutil/mem.h"
+#include "libavutil/thread.h"
#include "avcodec.h"
#include "internal.h"
#include "jpeg2000.h"
@@ -157,7 +158,7 @@ static int getsgnctxno(int flag, uint8_t *xorbit)
return ctxlbltab[hcontrib][vcontrib];
}
-void av_cold ff_jpeg2000_init_tier1_luts(void)
+static void av_cold jpeg2000_init_tier1_luts(void)
{
int i, j;
for (i = 0; i < 256; i++)
@@ -169,6 +170,12 @@ void av_cold ff_jpeg2000_init_tier1_luts(void)
getsgnctxno(i + (j << 8), &ff_jpeg2000_xorbit_lut[i][j]);
}
+void av_cold ff_jpeg2000_init_tier1_luts(void)
+{
+ static AVOnce init_static_once = AV_ONCE_INIT;
+ ff_thread_once(&init_static_once, jpeg2000_init_tier1_luts);
+}
+
void ff_jpeg2000_set_significance(Jpeg2000T1Context *t1, int x, int y,
int negative)
{