From 982a1d295c56f0398d69263947b50475aee64b34 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Fri, 23 Mar 2018 16:33:20 +0100 Subject: [PATCH] Fix a thread race in X264Encoder. Found by GCC TSan. --- x264_encoder.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/x264_encoder.cpp b/x264_encoder.cpp index ccf6942..66c0634 100644 --- a/x264_encoder.cpp +++ b/x264_encoder.cpp @@ -343,7 +343,12 @@ void X264Encoder::encode_frame(X264Encoder::QueuedFrame qf) } if (speed_control) { - speed_control->before_frame(float(free_frames.size()) / X264_QUEUE_LENGTH, X264_QUEUE_LENGTH, 1e6 * qf.duration / TIMEBASE); + float queue_fill_ratio; + { + lock_guard lock(mu); + queue_fill_ratio = float(free_frames.size()) / X264_QUEUE_LENGTH; + } + speed_control->before_frame(queue_fill_ratio, X264_QUEUE_LENGTH, 1e6 * qf.duration / TIMEBASE); } dyn.x264_encoder_encode(x264, &nal, &num_nal, input_pic, &pic); if (speed_control) { -- 2.39.2