diff mbox

[FFmpeg-devel] lagarith: assign correct per-thread value to LagarithContext::avctx.

Message ID 1490746312-62158-1-git-send-email-rsbultje@gmail.com
State Accepted
Commit 081c21ca55d72921125848c8c2c191a6ff8b5f88
Headers show

Commit Message

Ronald S. Bultje March 29, 2017, 12:11 a.m. UTC
This fixes race conditions reported by tsan in fate-lagarith. The races
were because each thread's LagarithContext::avctx was set to the first
thread's AVCodecContext.
---
 libavcodec/lagarith.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

Comments

Paul B Mahol March 29, 2017, 9:36 p.m. UTC | #1
On 3/29/17, Ronald S. Bultje <rsbultje@gmail.com> wrote:
> This fixes race conditions reported by tsan in fate-lagarith. The races
> were because each thread's LagarithContext::avctx was set to the first
> thread's AVCodecContext.
> ---
>  libavcodec/lagarith.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
>

LGTM
diff mbox

Patch

diff --git a/libavcodec/lagarith.c b/libavcodec/lagarith.c
index f03305f..469eec4 100644
--- a/libavcodec/lagarith.c
+++ b/libavcodec/lagarith.c
@@ -730,6 +730,16 @@  static av_cold int lag_decode_init(AVCodecContext *avctx)
     return 0;
 }
 
+#if HAVE_THREADS
+static av_cold int lag_decode_init_thread_copy(AVCodecContext *avctx)
+{
+    LagarithContext *l = avctx->priv_data;
+    l->avctx = avctx;
+
+    return 0;
+}
+#endif
+
 static av_cold int lag_decode_end(AVCodecContext *avctx)
 {
     LagarithContext *l = avctx->priv_data;
@@ -746,6 +756,7 @@  AVCodec ff_lagarith_decoder = {
     .id             = AV_CODEC_ID_LAGARITH,
     .priv_data_size = sizeof(LagarithContext),
     .init           = lag_decode_init,
+    .init_thread_copy = ONLY_IF_THREADS_ENABLED(lag_decode_init_thread_copy),
     .close          = lag_decode_end,
     .decode         = lag_decode_frame,
     .capabilities   = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,