summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-11-28 23:23:22 +0100
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-12-02 16:11:50 +0100
commit0639f5c294c70c55f4da75ce2ca5bf6c5a809248 (patch)
tree53085f4c4add7758d9be4476dcb74ef978979ec1
parent4e26520039ad7b45fc8d46fa7274e96cc0bdf8f9 (diff)
downloadffmpeg-0639f5c294c70c55f4da75ce2ca5bf6c5a809248.tar.gz
avcodec/pthread_slice: Don't use static variable, fix race
ff_slice_thread_init() uses a static variable to hold a function pointer, although the value of said pointer needn't be saved between different runs of this function at all. The reason for this being so is probably that said pointer points to a static function (if used); but storage class specifiers like "static" are not part of the type of an object and so including it in the pointer declaration is wrong (anyway, "static" means different things in both contexts: for the function declaration it affects linkage, for the variable storage duration). Using a static variable here can lead to races, e.g. when initializing VP9 (for which said function pointer was added) and H.264 with slice threading. The latter has the FF_CODEC_CAP_INIT_THREADSAFE flag set and is therefore unaffected by the lock guarding initializations of decoders. Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
-rw-r--r--libavcodec/pthread_slice.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/libavcodec/pthread_slice.c b/libavcodec/pthread_slice.c
index 77cfe3c9f6..80c4579fc0 100644
--- a/libavcodec/pthread_slice.c
+++ b/libavcodec/pthread_slice.c
@@ -130,7 +130,7 @@ int ff_slice_thread_init(AVCodecContext *avctx)
{
SliceThreadContext *c;
int thread_count = avctx->thread_count;
- static void (*mainfunc)(void *);
+ void (*mainfunc)(void *);
// We cannot do this in the encoder init as the threads are created before
if (av_codec_is_encoder(avctx->codec) &&