From patchwork Wed Mar 29 14:12:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ronald S. Bultje" X-Patchwork-Id: 3173 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.44.195 with SMTP id s186csp1111317vss; Wed, 29 Mar 2017 07:12:56 -0700 (PDT) X-Received: by 10.223.155.200 with SMTP id e8mr707104wrc.74.1490796776185; Wed, 29 Mar 2017 07:12:56 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id l44si8665862wrl.51.2017.03.29.07.12.55; Wed, 29 Mar 2017 07:12:56 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 460CC689AFF; Wed, 29 Mar 2017 17:12:15 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk0-f194.google.com (mail-qk0-f194.google.com [209.85.220.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 31E5D689A72 for ; Wed, 29 Mar 2017 17:12:08 +0300 (EEST) Received: by mail-qk0-f194.google.com with SMTP id f11so2164610qkb.2 for ; Wed, 29 Mar 2017 07:12:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Mhviu3lcZl/ZOeumPpMUjgDjCuB8BNDQSB1L7IDQ1pM=; b=leSnxG1aLeNpbz31oeykRfT4dg9F0btVP4zVWrjXUclN4vhy2GdpxIcFWL8YTIWuUT YfuLVu2tVWFMXG594lLDeRhMaD8ZaI1UhXDvvXGXCCAyQEgz1DunzP8bt1DxRDGkFGr8 xYDlSXY4utyxidP4/tbFMjy1aR301cz/e+bbKY/LfARufKW4eRa754f1QZCa1Wtc7a/5 TyrZIjPxIQYZBiCGlewV2SuDbxESCffGL8XqQmJjuDdtLJIW03mMsdWuwFEhhyBCJ+I+ VYMTBO4Bv3LBcOdwyLmo60XxDBDmvJ2ORZ95pMPOCUV3gykRlSab8AuKNH9jNTpoMpfb 7aIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Mhviu3lcZl/ZOeumPpMUjgDjCuB8BNDQSB1L7IDQ1pM=; b=Rw52rJhWt2fSb5cfGVcbujaJI9d9jY/UvKkFA7yJKyDDTX06CgzfxrIhMjxQTjjIrh FyFvcu2f2FI5UJo/Gg7VAKD6Bep46Fh30peZfe0YJhHjSXa/ADDqIWag96G0htI11hWX ASzxDhQ64FB4CMi/0CRTPaoCjtnoLMuOvoSbGHr/3qzE0PRbDsPeKCS/Ex1YfcxET70N GmTdw1dOr68MHv1Bl6SOs9PHHAy/EOPKi3OBH5ZPu7yxJiU+mZwzIPC64OsZR02cwTeN UwrkELwjCLvtxol3poYDntfVNP1XTI1z+9LDul+1Q7gzfGRcQ4PSU26W+43ZpxybahuL hQcw== X-Gm-Message-State: AFeK/H26vg1syassRbwIOLWijbQXW52AzgLn2UTZDayY9CUSKZATyFS7t1j0ga/egw+1vA== X-Received: by 10.233.232.6 with SMTP id a6mr719319qkg.53.1490796749926; Wed, 29 Mar 2017 07:12:29 -0700 (PDT) Received: from localhost.localdomain ([65.206.95.146]) by smtp.gmail.com with ESMTPSA id u63sm4976197qkh.45.2017.03.29.07.12.29 (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 29 Mar 2017 07:12:29 -0700 (PDT) From: "Ronald S. Bultje" To: ffmpeg-devel@ffmpeg.org Date: Wed, 29 Mar 2017 10:12:21 -0400 Message-Id: <1490796744-76454-3-git-send-email-rsbultje@gmail.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1490796744-76454-1-git-send-email-rsbultje@gmail.com> References: <1490796744-76454-1-git-send-email-rsbultje@gmail.com> Subject: [FFmpeg-devel] [PATCH 3/6] pthread_frame: call update_context_from_user() after acquiring lock. X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: "Ronald S. Bultje" MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Otherwise the thread may still be in the middle of decoding a previous frame, which would effectively trigger a race condition on any field concurrently read and written. --- libavcodec/pthread_frame.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c index 34c36d8..6cc43f6 100644 --- a/libavcodec/pthread_frame.c +++ b/libavcodec/pthread_frame.c @@ -379,7 +379,8 @@ static void release_delayed_buffers(PerThreadContext *p) } } -static int submit_packet(PerThreadContext *p, AVPacket *avpkt) +static int submit_packet(PerThreadContext *p, AVCodecContext *user_avctx, + AVPacket *avpkt) { FrameThreadContext *fctx = p->parent; PerThreadContext *prev_thread = fctx->prev_thread; @@ -391,6 +392,12 @@ static int submit_packet(PerThreadContext *p, AVPacket *avpkt) pthread_mutex_lock(&p->mutex); + ret = update_context_from_user(p->avctx, user_avctx); + if (ret) { + pthread_mutex_unlock(&p->mutex); + return ret; + } + release_delayed_buffers(p); if (prev_thread) { @@ -479,10 +486,7 @@ int ff_thread_decode_frame(AVCodecContext *avctx, */ p = &fctx->threads[fctx->next_decoding]; - err = update_context_from_user(p->avctx, avctx); - if (err) - goto finish; - err = submit_packet(p, avpkt); + err = submit_packet(p, avctx, avpkt); if (err) goto finish;