From patchwork Mon Mar 6 19:47:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muhammad Faiz X-Patchwork-Id: 2769 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.50.79 with SMTP id y76csp238724vsy; Mon, 6 Mar 2017 11:54:37 -0800 (PST) X-Received: by 10.223.155.135 with SMTP id d7mr14606762wrc.99.1488830077232; Mon, 06 Mar 2017 11:54:37 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 38si1778121wrv.191.2017.03.06.11.54.36; Mon, 06 Mar 2017 11:54:37 -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; 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 DDEF0688263; Mon, 6 Mar 2017 21:54:12 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf0-f195.google.com (mail-pf0-f195.google.com [209.85.192.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3670A680A98 for ; Mon, 6 Mar 2017 21:54:06 +0200 (EET) Received: by mail-pf0-f195.google.com with SMTP id v190so7666402pfb.0 for ; Mon, 06 Mar 2017 11:54:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=DIgja4Tz33sNy+MRgMU0lR81WMBBlxUZLjm3Gzxbpws=; b=g78inikeKq8bZSuoIU7/OL2OPVbroynKgaikyrtaSB7jX8lXKdmlXAnPBKn8tfkZeK eO7hE/fuXqbZuEw3g3uIoDMLXIAyxRT4qy9AydS2ob6MLjt1Ew7Ome6SElu2wGlWshGz P9uQiQLrlfFTCS1atrf6wsEgvGIHNYiGqIDmMxlvd/J/wlJm0QkcK/Y6Q2tVkP+uy9XT 91RT922U1gGJ8aYNZac27egL5EbP2RmSTTaxaQAjJdIO3oegK/mHOPu4UtlLF+VVXCNy qUaBPKepT9NSkoANq+Li24wdS93pJvh1h42k3+wjrgBUNGN9F2wYO7H5l8uUhzqLewKJ Yh9Q== 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; bh=DIgja4Tz33sNy+MRgMU0lR81WMBBlxUZLjm3Gzxbpws=; b=KYI3fGJirM99xaCs2GKDblYkJsPKSSx57B6+0QY3a2x6r6lI3I9xlOig1L4R9kF/i5 163L64ebqNs7nTTP2Y6qGNR7HpA6KXBLB9JzLToHKtISJO3YJgcVrjp0HXgStkNSorZf kKIe6qMBqYfYheePu2MfGCz6i1bcbzPzxHMHxepnAaVK2OoEQGeHU2criM+7TPPwmNPl qKc7VtVRK4SWXQ04XuYIu+1/QZpUphG/QYsghE86Rj0suRCSx0PtLeCDXsWiLyq3h1wX +uc5bNeXWDR/rf9r0hfd4CzGwARhtAmidgATp0xh6fVVqSHqHkBXB5R7c0pGWN04c/cf B39g== X-Gm-Message-State: AMke39lvAKtyglUuqNSN8duL0abQ++X5Pnc9nxBXdDNXbdLUslr0S4vuWlmPB3u3GPcRsg== X-Received: by 10.98.81.6 with SMTP id f6mr23053992pfb.180.1488829684763; Mon, 06 Mar 2017 11:48:04 -0800 (PST) Received: from localhost.localdomain ([114.120.237.152]) by smtp.gmail.com with ESMTPSA id p4sm41362446pgd.50.2017.03.06.11.47.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Mar 2017 11:48:04 -0800 (PST) From: Muhammad Faiz To: ffmpeg-devel@ffmpeg.org Date: Tue, 7 Mar 2017 02:47:36 +0700 Message-Id: <20170306194739.1870-1-mfcc64@gmail.com> X-Mailer: git-send-email 2.9.3 Subject: [FFmpeg-devel] [PATCH 1/4] avcodec/allcodecs: make avcodec_register_all thread safe 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: Muhammad Faiz MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Muhammad Faiz --- libavcodec/allcodecs.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index eee322b..1d05fc1 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -24,6 +24,8 @@ * Provide registration of all codecs, parsers and bitstream filters for libavcodec. */ +#include + #include "config.h" #include "avcodec.h" #include "version.h" @@ -60,11 +62,14 @@ void avcodec_register_all(void) { - static int initialized; + static atomic_int initialized; + static atomic_int ready; - if (initialized) + if (atomic_exchange_explicit(&initialized, 1, memory_order_relaxed)) { + while (!atomic_load_explicit(&ready, memory_order_relaxed)) + ; return; - initialized = 1; + } /* hardware accelerators */ REGISTER_HWACCEL(H263_VAAPI, h263_vaapi); @@ -716,4 +721,6 @@ void avcodec_register_all(void) REGISTER_PARSER(VP8, vp8); REGISTER_PARSER(VP9, vp9); REGISTER_PARSER(XMA, xma); + + atomic_store_explicit(&ready, 1, memory_order_relaxed); }