From patchwork Thu Jan 4 18:19:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 7121 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.78.2 with SMTP id r2csp558912jaa; Thu, 4 Jan 2018 10:19:40 -0800 (PST) X-Google-Smtp-Source: ACJfBouVMj2a89qHO4tM63XmP/pUsXpOnHMgYx+RKlk3ucMOkVfaYTU4lBGS9fRoDtrdUV0Eo+vN X-Received: by 10.28.142.7 with SMTP id q7mr345458wmd.50.1515089979961; Thu, 04 Jan 2018 10:19:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515089979; cv=none; d=google.com; s=arc-20160816; b=L4G/xFKvn+/Dm9ylbnf5HYBJspqy/OS+K6rNKPBtWwT0u7yKSy/aa+3Am4JSHAFMqx Xt/M1w7AfaM7wLT4rdQUgHA3YFJsKqvQz/VvfO0kdMGWY9UJjw2414GinJ6C0fTvB7c/ C9WOQNPPDkC6QfgRGIlfflnxKKKWCP3SdQGJJ4TWqQHzJTUlVaju067KIuoYW789UsJ5 ABk1YDmpsdougj/MS8ZoRSuWwWWUE+v0ArYmA6Rc6MDYPe1W/69gKWg9gEmhh6ag/w92 0Jsy6L645XrqF9qzdYvFLgTeyGRb94v/x6YKQabZ06/1g7zvdRovxQZjfkSM2TRw9zto f/Xg== 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=ZxKXwf7FpU2eQnXec01wws8gOVjamtv6G84NTonpB9o=; b=QAM6ycZaIqrzHoTtjgeS50GWvz3iTjjrmit+S3gzMv9A9H5yrvl67NyzD4dqGClfus kId26vhH2e56Rfhmoi3SBXm9kwAo7WbasLiPNRZBK7NuRqUjo6gPW1NBlhrgt8l/Jc7r WFrfJwcIaUeZ7HuNlTUFUPs0pTRwVWvpFTQSLKD/qkjckM6X/CbhenqJxDbAYgQgg3KC W967cVEvCdD7Kfp6Pp6SrWIKR5H5bpkijZSKKV1YjCwTH9utZOpWQAJfxv9PpbVfIozv HTA9D8lY58CI0fUcDJvJSj71LnN9ysTZicqa6E/9eKRFDMWuiykhpCFsY0oemrZ7lWMX g8+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=AvTPIzf5; 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 m1si2493246wmm.143.2018.01.04.10.19.39; Thu, 04 Jan 2018 10:19:39 -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=AvTPIzf5; 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 41B1E689957; Thu, 4 Jan 2018 20:19:08 +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 CA59568993D for ; Thu, 4 Jan 2018 20:19:01 +0200 (EET) Received: by mail-qk0-f196.google.com with SMTP id c5so2994074qkg.6 for ; Thu, 04 Jan 2018 10:19: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=B/HznG5FJyoHa2u5ZGGxcvRDX0B1stHFEMSdQ0PMWbg=; b=AvTPIzf5cC8CgHSaVG75Xuxo/k1USqOMI7njMA7Oe0XFXh9i44K3jbvcWuW5/WMb7H qNQ0erMSZ2LTMDL3GbmbjwTtRueh77Au0o7oEOy0uIt0IB/mKwxMyKMNQB989nWFVFQt /JRXwGYO3IHKTriJVjmtqSdj2ioBZEGDCQZaC/0ThFdXzjXp9ncd1VRgzxjtvfeA1fQe Zk8PFKl+VvpYiWURTUoBtf0NLXYetFy6LRLqY2VCrzEN2ybihf5Pd+Q8cSnz35CBlC08 ezBQatF03AKVPES1bZnfBPJPqBm4LtbpQP482N/gJL8TGM1VqH2jwchp+3FqN5GLNjL3 TfwA== 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=B/HznG5FJyoHa2u5ZGGxcvRDX0B1stHFEMSdQ0PMWbg=; b=Ad/rumsf1teQAiXB5rgGkCOtFne2Kcd9LAbWP1JT5JjTqEPWhQIR+sEcu4gnFFsidj 7FYKxVVcm+BUaKbMTOSMxXZdVAtQNH4XART3Fx61HgmdqVqUzZGCpSpSHXY0hkumCDtm HnLCc7Oy82jFJTRJ7tnHSZQDzkpdq3fQQec+ddBfX46dViFB1TiAQNvBOzbgiyH7o20u IwwX333usc/129JSG5wsOiIQWvmTviXoFxoL4rVtvDxHf5CmG2cQcacErChawueX6ntd f2o/6lOOGCsDxtIWK7VK2C4LjuV8O6C4wBPCFQ8PxkjOCmsr5JDfViLWVS6ZNL/FD0dT 0GAg== X-Gm-Message-State: AKwxytdBV0aLIIHsZjMfM/UtAeXxpK01tJD2EJBoHS7hH/quqa02LsuV X4ntE6YmrpxHIiA4lhor3E8tzA== X-Received: by 10.55.176.2 with SMTP id z2mr607637qke.13.1515089957649; Thu, 04 Jan 2018 10:19:17 -0800 (PST) Received: from localhost.localdomain ([181.229.225.176]) by smtp.gmail.com with ESMTPSA id n81sm2488321qki.87.2018.01.04.10.19.16 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 04 Jan 2018 10:19:17 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Thu, 4 Jan 2018 15:19:03 -0300 Message-Id: <20180104181904.5816-3-jamrial@gmail.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20180104181904.5816-1-jamrial@gmail.com> References: <20180104181904.5816-1-jamrial@gmail.com> Subject: [FFmpeg-devel] [PATCH 3/4] 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 | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/libavformat/format.c b/libavformat/format.c index 38ca2a3465..bc443f41ce 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" @@ -39,9 +39,6 @@ static AVInputFormat *first_iformat = NULL; /** head of registered output format linked list */ static AVOutputFormat *first_oformat = NULL; -static AVInputFormat **last_iformat = &first_iformat; -static AVOutputFormat **last_oformat = &first_oformat; - AVInputFormat *av_iformat_next(const AVInputFormat *f) { if (f) @@ -58,28 +55,38 @@ 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 = &first_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; - if (!format->next) - last_iformat = &format->next; + *p = format; + format->next = NULL; + 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 = &first_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; - if (!format->next) - last_oformat = &format->next; + ff_mutex_unlock(&oformat_register_mutex); } int av_match_ext(const char *filename, const char *extensions)