From patchwork Fri Jan 5 01:41:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 7131 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.78.2 with SMTP id r2csp181787jaa; Thu, 4 Jan 2018 17:42:25 -0800 (PST) X-Google-Smtp-Source: ACJfBouWfKidJvX30mJU7cVStEL+ZYFrFzIWsKLeSTFIZyL7NfpO0X7AwXfR/9/N6iMwAgnbOxCY X-Received: by 10.223.156.145 with SMTP id d17mr1202672wre.198.1515116545064; Thu, 04 Jan 2018 17:42:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515116545; cv=none; d=google.com; s=arc-20160816; b=V7v+XjRMW3/gfqGhqwYkH7dS8kp/7nNcYcUS38b0eUt32v1v0AEi8jf388SYe6mG4H 8/KEQa1pHruvs7HTH6oDSHiRkSXU9U52hn5Ay/X0SUOQrKT1OfSYYse8NEtfgwGm/8/8 I6YgIk+BFU/0lcwG+HrPBXJTCWcLrJxWkrFT5nR5xEdu3LMEVSmdKCUuB3huWCMDmJ+O aaqxOmxFMleKGvC2bCrwTMGXFo4ojgE4MC1stlHLaCTlAmpO5lxsEZyONdywMJF5W1sJ GTCxTHlyVlBYlbQY8kka5ehEvx8wI10zofAhhvMqREReG0NE8V7X8f0ROx5iZL+6N2AS wF+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=pmSDtWIJ83GB21DXn8XUK7uoIBGkxXrgyjo+5nGj+uI=; b=PVT4wNr/gTR+nQ+IFOeDkNquSK0cY30UvAzlw/HL5uaVEPU7nu0mzleqULJhU0WvGW alCFeQHh1tNhSdYfLIE/FR3InEJL8+W5/70cnOA1q8BmcaF1Yahe+9zk8e6zdnPcgs+z 0vyp+VIvqmsdzc6vJRNvi4BhnyJFLN1DyYYLQf7oL7pwtjK2Iv+xCNzSuRtNDeAMQdva urJuTgMyDPvb9hSYl46iN1nTuIQQxvxFmveM2IIcNJQamPO4S1HWRzwUeJh7YtlqFtRs aaQgDMg/TPxPDPtmiL9Fc0FGhGLTyTfHBL8KT/5QEeex+bDLyDZK07cN8VGp4RFKs78P 0w3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=iXTkmAzA; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id h133si2872897wmf.152.2018.01.04.17.42.24; Thu, 04 Jan 2018 17:42:25 -0800 (PST) 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 header.s=20161025 header.b=iXTkmAzA; 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 EC9C66898B9; Fri, 5 Jan 2018 03:42:06 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk0-f196.google.com (mail-qk0-f196.google.com [209.85.220.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E36896882FD for ; Fri, 5 Jan 2018 03:42:00 +0200 (EET) Received: by mail-qk0-f196.google.com with SMTP id p13so4289609qke.4 for ; Thu, 04 Jan 2018 17:42:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=6s1+7lH2EC5DyB6LPSjOhhEElVKY/82J2Sz/prbxSmA=; b=iXTkmAzAKU9gHvRxVB/mBrbd+zX9mkcpl95wRYi3z4EZuzfZVzf5+3AOLqE7tVUo3k BnIpmF8IV/nFgHsRvMDvUH3kjX5cPQR5sUUaCdhwx2F23HN6W4rDRjKDgQhwlM1YlW2h EesOotjtla/FeZyuYUkB8NF2n1pg8f5R7esyr3Qyl65don6W4Wimm02g56xfLHsjGDYS OP3THf1gSHqluoOHsPhnwVlol+l2aMUtGmwns9UgkvuDplZ+gDUE3GhvjcIIu5Y+5QJ4 tHQw7AJo8uYWkgAiXVsomUeXnbYQy8aRZa5Q3MYIaoEIp6XK8VArVpJa6yTbmQNrQ0+B dM1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=6s1+7lH2EC5DyB6LPSjOhhEElVKY/82J2Sz/prbxSmA=; b=UPbDv2fXoSGYpkKdYAjisSIoe80ZLrgLDTcwRITxlHVszBa8qkR9jZ9ExBTz+kncoG m7paHyVrXlCDQh7DcCsR2S+7MpCcRn9rv8ecIwuYwImiKEAa1t1mPcJabRdXUswzdTRP /FEJi0tPdvOg41pjIAlPrUqq+GLHouXeuwyHuHdCgVepXyeOqZCZ1fFsdyh11OxL3fqX zoSq/Dq00gfJJ9r5CGn9to5QT90AFyViFBZOwNmVSwGYe1I+g+SojXGY/W6UKi6bYejS 6Y4s4E0VfCefV+w6VfBEoASS1mx8QLMgfnimr0LHzBrljZgjqi7HPmnUUoAn03qIYinY UO4w== X-Gm-Message-State: AKwxyte+xLEQwp+c0mT6SDTleg1MVicLV5Fuz9DVy7f/VusJ8mJB9mu7 jJrr7LK78gHPn2h7LTQABY2vww== X-Received: by 10.55.20.234 with SMTP id 103mr1034944qku.274.1515116536791; Thu, 04 Jan 2018 17:42:16 -0800 (PST) Received: from localhost.localdomain ([181.229.225.176]) by smtp.gmail.com with ESMTPSA id d10sm2971111qkg.16.2018.01.04.17.42.15 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 04 Jan 2018 17:42:16 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Thu, 4 Jan 2018 22:41:38 -0300 Message-Id: <20180105014138.10156-1-jamrial@gmail.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20180104181904.5816-3-jamrial@gmail.com> References: <20180104181904.5816-3-jamrial@gmail.com> Subject: [FFmpeg-devel] [PATCH 2/3 v2] avformat: use mutexes instead of atomics in av_register_{input, output}_format() 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: James Almer --- libavformat/format.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/libavformat/format.c b/libavformat/format.c index 38ca2a3465..759b5b1ab4 100644 --- a/libavformat/format.c +++ b/libavformat/format.c @@ -19,10 +19,10 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "libavutil/atomic.h" #include "libavutil/avstring.h" #include "libavutil/bprint.h" #include "libavutil/opt.h" +#include "libavutil/thread.h" #include "avio_internal.h" #include "avformat.h" @@ -58,28 +58,40 @@ AVOutputFormat *av_oformat_next(const AVOutputFormat *f) return first_oformat; } +static AVMutex iformat_register_mutex = AV_MUTEX_INITIALIZER; + void av_register_input_format(AVInputFormat *format) { - AVInputFormat **p = last_iformat; + AVInputFormat **p; + + ff_mutex_lock(&iformat_register_mutex); + p = last_iformat; - // Note, format could be added after the first 2 checks but that implies that *p is no longer NULL - while(p != &format->next && !format->next && avpriv_atomic_ptr_cas((void * volatile *)p, NULL, format)) + while (*p) p = &(*p)->next; + *p = format; + format->next = NULL; + last_iformat = &format->next; - if (!format->next) - last_iformat = &format->next; + ff_mutex_unlock(&iformat_register_mutex); } +static AVMutex oformat_register_mutex = AV_MUTEX_INITIALIZER; + void av_register_output_format(AVOutputFormat *format) { - AVOutputFormat **p = last_oformat; + AVOutputFormat **p; + + ff_mutex_lock(&oformat_register_mutex); + p = last_oformat; - // Note, format could be added after the first 2 checks but that implies that *p is no longer NULL - while(p != &format->next && !format->next && avpriv_atomic_ptr_cas((void * volatile *)p, NULL, format)) + while (*p) p = &(*p)->next; + *p = format; + format->next = NULL; + last_oformat = &format->next; - if (!format->next) - last_oformat = &format->next; + ff_mutex_unlock(&oformat_register_mutex); } int av_match_ext(const char *filename, const char *extensions)