From patchwork Thu Nov 30 11:54:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rostislav Pehlivanov X-Patchwork-Id: 6471 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.94 with SMTP id m30csp529937jah; Thu, 30 Nov 2017 03:59:47 -0800 (PST) X-Google-Smtp-Source: AGs4zMZnsDvGstHD7hf/TJIQSYgUVRYsx3zAta0jHo5HA+d50SY05GiipZFTzBJDqmw8C4dO2WNy X-Received: by 10.223.164.84 with SMTP id e20mr1896728wra.52.1512043187094; Thu, 30 Nov 2017 03:59:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512043187; cv=none; d=google.com; s=arc-20160816; b=Mcj6cOxMF9UcApUN7mWe50/+F9VMi6EBCIuS1qT2UghmlaWaNNzoclLn/GOZXk5TL7 erOx9KoUC4gev5kyrjv6142ju8snHm7RlOobcfsGufGzfQoGzc9BrLizFZLnHyrMMk5d l/ocVdJCGRDHQpVU5lVA0sdbJoWHZ+wAIG31Zi/kt3oeRn3b6E3MpyA6WSwjLs1bDyUr 6nMMBFOwyf+TcDIP9vsx0j+F4OomLQEBYNabWrfujv9+8ExOgqhnCGD4OuKAePOEGgK0 d75EXfRFtlEinxf2K3J3uqf8Xrh9mc9YgrB3YzgwiDIY/xloYGyoiFlweFcVx68dBRPp Dp9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject:to :message-id:date:from:references:in-reply-to:mime-version :dkim-signature:delivered-to:arc-authentication-results; bh=1Yig6u6KomnjcNAZIjcfg2SpzgOK9zvqCw18Xg0dAG4=; b=MxVptsVEXEPYdsWBclO3Ocip9r5VdQ0ShkdqYkgb89ZThq6Nb7R2qUG/OA6rfz21uO 679X6AliktpZng6yCiTr4ZHRM59b5Lgzeb88wtrB3o25NLx4i2QM8QPfm42NMf6YepzC 18Hsacs64EpSmqwED4EhGURoDXz4pk3YZllJHjWeF8clsqUwdxi6ZqWxyBwidtypzQnh LR1+UAj5DFAysrZLcJBzw95DmCemBsl9B7PlpiZkCIPOWsOo5VhoHRcM6Thkdax//P2h x8Xlpc9JsUlZt6Oj2tRA7QJZlE997OLGaTpoC5OLZ3hDuWlZ9mpweVYkelfFzeq3P6j6 hOfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=biv5B0eN; 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 y54si3059381wry.87.2017.11.30.03.59.46; Thu, 30 Nov 2017 03:59:47 -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=biv5B0eN; 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 3F63868A390; Thu, 30 Nov 2017 13:59:42 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk0-f178.google.com (mail-qk0-f178.google.com [209.85.220.178]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A9C5A689B04 for ; Thu, 30 Nov 2017 13:59:35 +0200 (EET) Received: by mail-qk0-f178.google.com with SMTP id b184so8412592qkc.13 for ; Thu, 30 Nov 2017 03:59:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=57a6EAe7GFjdOrb2tZBdW+v/gewH4HQ6vKAbx4mmE50=; b=biv5B0eNENdu4pKkZqMWI57BbZ863ZPEDDoyvnxKM18L4hFjd0d2oSsXVoIFIJ0I2p dtX+/eCA1MMHp/mVUKtG5K2Xhqn4tYFtXIzWuEZJfJcJNQdOOG7lQuldwicNj/0AXbye 3Sq8zv8yMt65qtPRrNn/ovZPjyvyntXqGlvfzxS156swgP8FparFGkazCEIeE0uU5L7C VT6CWTK9DmsyGdLh2Q0gvSmaRNlutgTGVTFyvQRnZRWHK2lLMhrFZwVXW2tAJCDbyiSf g6y57M3+SoUe3U4WptalSAJQp8FBTAMwK91w9fl/GFxir/vlc55XhO2HQMkTBNcQjYqn pjcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=57a6EAe7GFjdOrb2tZBdW+v/gewH4HQ6vKAbx4mmE50=; b=G+OZR/YQVuHG6+cGCfMxGR0yj66gjKVYwmVFrlONaqQW7obYCa/o7KPngqxoUHPuNc dmhgzx0n6861Xgr8YaR4aDMr/HYWZ/KCcyDc48rjuFkIk1fYmD421JrJ6p4iFNyY+JX9 +67NFfu2upU2gP2qoHyAAwJ2zSvVGj4S/M/PFA7eGb5jjinPYY92s6mH5k8naOcdQBPS 5KyOUuKLKP2XSMN+ly8v/ty0hKTZxXYu3ibBkuTdY/QUIDnhtwDNTXeOTh5XkicWWaj4 /D4QfKvQwstQ1opYJOpOCtEJ3rhJVk8kp10w0iqN8C599/DqfYapG71Krk2ELBbBYIy3 Tx3w== X-Gm-Message-State: AKGB3mJU8Pk7qps1QFezg2jeMvYfgtAVeaP0dfMbYzzfaKOl79eMI4gu IjEaKGOzuNmjcsiXVnytfS2k3ASzMPZo4GP/TNtuhQ== X-Received: by 10.55.53.84 with SMTP id c81mr2192216qka.185.1512042866759; Thu, 30 Nov 2017 03:54:26 -0800 (PST) MIME-Version: 1.0 Received: by 10.140.28.117 with HTTP; Thu, 30 Nov 2017 03:54:25 -0800 (PST) In-Reply-To: <20171129164012.GL4636@nb4> References: <20171127043021.20321-1-atomnuker@gmail.com> <20171127043021.20321-2-atomnuker@gmail.com> <20171128202358.GB4636@nb4> <20171129164012.GL4636@nb4> From: Rostislav Pehlivanov Date: Thu, 30 Nov 2017 11:54:25 +0000 Message-ID: To: FFmpeg development discussions and patches X-Content-Filtered-By: Mailman/MimeDel 2.1.20 Subject: Re: [FFmpeg-devel] [PATCH 2/4] lavfi/avfilter: simplify filter registration 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" On 29 November 2017 at 16:40, Michael Niedermayer wrote: > On Wed, Nov 29, 2017 at 03:51:34AM +0000, Rostislav Pehlivanov wrote: > > On 28 November 2017 at 20:23, Michael Niedermayer > > > wrote: > > > > > On Mon, Nov 27, 2017 at 04:30:19AM +0000, Rostislav Pehlivanov wrote: > > > > Atomics were entirely pointless and did nothing but slow and > complicate > > > > the process down. This could be improved further still but the main > > > > objective of this commit is to simplify. > > > > > > > > Signed-off-by: Rostislav Pehlivanov > > > > --- > > > > libavfilter/avfilter.c | 8 +++++--- > > > > 1 file changed, 5 insertions(+), 3 deletions(-) > > > > > > *_register() can be called by the user app in a unsyncronized way > > > for example from a module like vlc used AFAIK. > > > or from libs loaded by an application which use libavfilter or other > > > internally. > > > > > > These registration functions should stay thread safe > > > > > > > > > [...] > > > > > > -- > > > Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC7 > 87040B0FAB > > > > > > Those who would give up essential Liberty, to purchase a little > > > temporary Safety, deserve neither Liberty nor Safety -- Benjamin > Franklin > > > > > > _______________________________________________ > > > ffmpeg-devel mailing list > > > ffmpeg-devel@ffmpeg.org > > > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > > > > > > > What variable actually needs to be protected? > > The linked list of registered "entities" > That is if the addition is not synchronized by some means, an atomic > exchange a mutex or something then a race can generally occur > and only one addition might succeed or something else might get > entangled > > This is in practical terms a very unlikely event to occur of course > > [...] > -- > Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB > > You can kill me, but you cannot change the truth. > > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > Could you test the attached patch? Pretty much everything is synchronized. From fb9789206c76c876d6a79e81df68c6b8041f03c3 Mon Sep 17 00:00:00 2001 From: Rostislav Pehlivanov Date: Mon, 27 Nov 2017 04:12:26 +0000 Subject: [PATCH v2 2/2] lavfi/avfilter: simplify filter registration Atomics were entirely pointless and did nothing but slow and complicate the process down. This could be improved further still but the main objective of this commit is to simplify. Signed-off-by: Rostislav Pehlivanov --- libavfilter/avfilter.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index b98b32bacb..76c9f12be9 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -19,7 +19,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "libavutil/atomic.h" #include "libavutil/avassert.h" #include "libavutil/avstring.h" #include "libavutil/buffer.h" @@ -37,6 +36,7 @@ #define FF_INTERNAL_FIELDS 1 #include "framequeue.h" +#include #include "audio.h" #include "avfilter.h" #include "filters.h" @@ -574,7 +574,7 @@ int avfilter_process_command(AVFilterContext *filter, const char *cmd, const cha } static AVFilter *first_filter; -static AVFilter **last_filter = &first_filter; +static _Atomic (AVFilter **) last_filter = ATOMIC_VAR_INIT(&first_filter); const AVFilter *avfilter_get_by_name(const char *name) { @@ -592,16 +592,16 @@ const AVFilter *avfilter_get_by_name(const char *name) int avfilter_register(AVFilter *filter) { - AVFilter **f = last_filter; - /* the filter must select generic or internal exclusively */ av_assert0((filter->flags & AVFILTER_FLAG_SUPPORT_TIMELINE) != AVFILTER_FLAG_SUPPORT_TIMELINE); filter->next = NULL; - while(*f || avpriv_atomic_ptr_cas((void * volatile *)f, NULL, filter)) - f = &(*f)->next; - last_filter = &filter->next; + /* Iterate through the list until the last entry has been reached */ + do { + *atomic_load(&last_filter) = filter; + atomic_store(&last_filter, &filter->next); + } while (*atomic_load(&last_filter)); return 0; } -- 2.15.1.424.g9478a66081