From patchwork Wed Mar 29 14:12:24 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: 3175 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.44.195 with SMTP id s186csp1111517vss; Wed, 29 Mar 2017 07:13:24 -0700 (PDT) X-Received: by 10.28.157.150 with SMTP id g144mr979375wme.89.1490796804503; Wed, 29 Mar 2017 07:13:24 -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 193si7395486wmq.1.2017.03.29.07.13.24; Wed, 29 Mar 2017 07:13:24 -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 8647A689B27; Wed, 29 Mar 2017 17:12:18 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt0-f196.google.com (mail-qt0-f196.google.com [209.85.216.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 44041689AD4 for ; Wed, 29 Mar 2017 17:12:11 +0300 (EEST) Received: by mail-qt0-f196.google.com with SMTP id r45so2146690qte.0 for ; Wed, 29 Mar 2017 07:12:34 -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=xc4Ug/rOr5wLbXlVrKOykkfOtUH70+PbThSLBoGW7hU=; b=XbCRBJxXqYwSxT2dq2WD6ci/l1i6WI3SGj4x9oUO+bwBAAKd/HkIVsTL03YwCv8zSK 5Qw8+aRqVgWXooGBvEwIrQDwfSZDPA4DKZspxb1njgfyYWNLwmxjtFUhGRMt21aD9vOf rTpn0OVGgLfXffaL7t1AwwqVsDJhpCyUp8Osev8RmZEK5u74kV9CJGgqQW6zi2Lor82b /LkzVqURkLshJY4oMP93uGsJc/TYnJOeOeo7AcDpqa3gSks0xAmubOysARpc2s/sLB1j kUa0PODrLsGhV6+D5qJ+77YZt8BYu9mvkkR25rzY7u1QiTQpEDY28Lcox5NZcePq1szT +TTA== 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=xc4Ug/rOr5wLbXlVrKOykkfOtUH70+PbThSLBoGW7hU=; b=VPY+dU0PboEaLzLeu/FJ72Hisyz4n5MMWHUsypcby3lqNjOLJHrud5p/+QS0lGOcR0 hfo1xulcHw6Es+cB4s6O3QJnRukEEj3sWImJbvy/8I1oAr6vj9Ebzqnb+dd/CUe8u48H 8kJ4JDorw3jMbn6KrbWoxBvnDQmy7vSvDjLwsxy1jd6k3WWN3lXlL8+y7Bv/KxJQOoz+ rCNP1RxztTWJ6/1NFhzes93mM1Nqo4FRPupwEqQxopDJSY8+WecMJcuhU1yWAS4YNsPm 1aybY+RYnrw1hyCxxRANzB5bonGarAypP5Uc0sQwk8mCuV3M9MJoGfvzqd8+K8F+S5hm 6Fbg== X-Gm-Message-State: AFeK/H18MQGbWvwFAKqtYpnD3j63u36W+mOKzForE18nwy3JF+FFTH/nV9rVu9DHvrM4QA== X-Received: by 10.200.38.39 with SMTP id u36mr880987qtu.58.1490796752724; Wed, 29 Mar 2017 07:12:32 -0700 (PDT) Received: from localhost.localdomain ([65.206.95.146]) by smtp.gmail.com with ESMTPSA id u63sm4976197qkh.45.2017.03.29.07.12.31 (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 29 Mar 2017 07:12:31 -0700 (PDT) From: "Ronald S. Bultje" To: ffmpeg-devel@ffmpeg.org Date: Wed, 29 Mar 2017 10:12:24 -0400 Message-Id: <1490796744-76454-6-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 6/6] frame_thread_encoder: make task indexing deterministic. 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" Fixes tsan warnings in fate-utvideoenc. --- libavcodec/frame_thread_encoder.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/libavcodec/frame_thread_encoder.c b/libavcodec/frame_thread_encoder.c index 27ae356..8db9290 100644 --- a/libavcodec/frame_thread_encoder.c +++ b/libavcodec/frame_thread_encoder.c @@ -251,6 +251,7 @@ int ff_thread_video_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVF ThreadContext *c = avctx->internal->frame_thread_encoder; Task task; int ret; + unsigned idx; av_assert1(!*got_packet_ptr); @@ -264,32 +265,33 @@ int ff_thread_video_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVF return ret; } - task.index = c->task_index; + task.index = c->task_index % BUFFER_SIZE; task.indata = (void*)new; pthread_mutex_lock(&c->task_fifo_mutex); av_fifo_generic_write(c->task_fifo, &task, sizeof(task), NULL); pthread_cond_signal(&c->task_fifo_cond); pthread_mutex_unlock(&c->task_fifo_mutex); - c->task_index = (c->task_index+1) % BUFFER_SIZE; + c->task_index++; - if(!c->finished_tasks[c->finished_task_index].outdata && (c->task_index - c->finished_task_index) % BUFFER_SIZE <= avctx->thread_count) + if (c->task_index - c->finished_task_index < avctx->thread_count) return 0; } if(c->task_index == c->finished_task_index) return 0; + idx = c->finished_task_index % BUFFER_SIZE; pthread_mutex_lock(&c->finished_task_mutex); - while (!c->finished_tasks[c->finished_task_index].outdata) { + while (!c->finished_tasks[idx].outdata) { pthread_cond_wait(&c->finished_task_cond, &c->finished_task_mutex); } - task = c->finished_tasks[c->finished_task_index]; + task = c->finished_tasks[idx]; *pkt = *(AVPacket*)(task.outdata); if(pkt->data) *got_packet_ptr = 1; - av_freep(&c->finished_tasks[c->finished_task_index].outdata); - c->finished_task_index = (c->finished_task_index+1) % BUFFER_SIZE; + av_freep(&c->finished_tasks[idx].outdata); + c->finished_task_index++; pthread_mutex_unlock(&c->finished_task_mutex); return task.return_code;