From patchwork Mon Nov 23 19:37:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23987 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id AE5C844A49B for ; Mon, 23 Nov 2020 21:38:18 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8DEA568BBBD; Mon, 23 Nov 2020 21:38:18 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6464768BB73 for ; Mon, 23 Nov 2020 21:38:10 +0200 (EET) Received: by mail-wm1-f65.google.com with SMTP id w24so405888wmi.0 for ; Mon, 23 Nov 2020 11:38:10 -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:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=wBoBvg12QPi3J+aqmD8gNIRWZgk26m2XISdLZT5W3cA=; b=ZTpE7iVi1PZ2Davdnjv5S9tJXqpHs3Yw5VwwEPO1QCogptF2JOZAFwi8QB8lsgkYKX hJkg77SfcsR/4HV0/jhX0A/MoqCou/qepf7JcSSqd6vF9+E260Z7L8NzdVwunYKAQL56 Kcy+2kdiD1s1ZXtT/qX49qfxGupScklaAqPWzNvTrCyXBAodP5CXfOqTu8nY77aLuEg3 h/IvjGJ0fC+fwkRHhUEks1VMA8/RTZjJWZ9qB8Q4YWq2E/GDKjp6sr+mTqid5WfW4ZcT PIkU7SKywm/24PyuaZFcyKz3BCMiZoOjOR8RxKJEp7Z+OFRh+uOoTmtxTcu6hLCBNUwM vZFQ== 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:reply-to:mime-version:content-transfer-encoding; bh=wBoBvg12QPi3J+aqmD8gNIRWZgk26m2XISdLZT5W3cA=; b=dsIKh4VxJb2SVc2dBm64BHw9jLNJ3agB5VBM20aahiC/JssMaCkUKnn9iOIXnyKxqL 8UrqDyKt9CaZwtXE8pcfW5PPRNWx3j70KA0jV5NFazwX5Z02/NkrSNVvALkuRqQJmSOM CXA6Y9v2sRs19CDJp8FUTbvSrPhIswtU3i39Bp2QPJkWyEvdITHKoE2o6Q3TDd+XCmFD GdfTOIbScpQA7msA4OQZiKGaTHm8QRfVQXMr2KydS3fldhl7z0aqC8kQBVCxeC00doUq tLomvmJR3TI6ho3syB56Xxhgr/LK2xcMclKLyFrfTDUWkonDmtC84tZqGOZOTj6va+d6 YttA== X-Gm-Message-State: AOAM5307/vQeo/bnBZLb8eU3oPfkMQavnibv1nqKD1g0cKdoF9h8GlNs IkI8UzD9/eP507zr1XD8s/+JJ9WJ6Mc6Ag== X-Google-Smtp-Source: ABdhPJzctebQ7943eKy+xmJsLdpXHsqKIEH2U7huc9xg1RW+JtexJY5sCzo36yWp6q9naCAghX4BNA== X-Received: by 2002:a1c:2e48:: with SMTP id u69mr511418wmu.30.1606160289521; Mon, 23 Nov 2020 11:38:09 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id e6sm564086wme.27.2020.11.23.11.38.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Nov 2020 11:38:08 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 23 Nov 2020 20:37:15 +0100 Message-Id: <20201123193739.1249300-5-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201120072116.818090-1-andreas.rheinhardt@gmail.com> References: <20201120072116.818090-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 167/191] avcodec/sinewin_tablegen: Make initializing ff_sine_windows 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Andreas Rheinhardt --- libavcodec/sinewin_tablegen.h | 43 ++++++++++++++++++++++++++ libavcodec/sinewin_tablegen_template.c | 1 + 2 files changed, 44 insertions(+) diff --git a/libavcodec/sinewin_tablegen.h b/libavcodec/sinewin_tablegen.h index 1959074189..ced3b7874c 100644 --- a/libavcodec/sinewin_tablegen.h +++ b/libavcodec/sinewin_tablegen.h @@ -32,6 +32,10 @@ #include "libavutil/common.h" #if !CONFIG_HARDCODED_TABLES +#ifndef BUILD_TABLES +#include "libavutil/thread.h" +#endif + SINETABLE( 32); SINETABLE( 64); SINETABLE( 128); @@ -69,10 +73,49 @@ av_cold void AAC_RENAME(ff_sine_window_init)(INTFLOAT *window, int n) { window[i] = SIN_FIX(sinf((i + 0.5) * (M_PI / (2.0 * n)))); } +#if !CONFIG_HARDCODED_TABLES && !defined(BUILD_TABLES) +#define INIT_FF_SINE_WINDOW_INIT_FUNC(index) \ +static void init_ff_sine_window_ ## index(void) \ +{ \ + AAC_RENAME(ff_sine_window_init)(AAC_RENAME(ff_sine_windows)[index], 1 << index);\ +} + +INIT_FF_SINE_WINDOW_INIT_FUNC(5) +INIT_FF_SINE_WINDOW_INIT_FUNC(6) +INIT_FF_SINE_WINDOW_INIT_FUNC(7) +INIT_FF_SINE_WINDOW_INIT_FUNC(8) +INIT_FF_SINE_WINDOW_INIT_FUNC(9) +INIT_FF_SINE_WINDOW_INIT_FUNC(10) +INIT_FF_SINE_WINDOW_INIT_FUNC(11) +INIT_FF_SINE_WINDOW_INIT_FUNC(12) +INIT_FF_SINE_WINDOW_INIT_FUNC(13) + +static void (*const sine_window_init_func_array[])(void) = { + init_ff_sine_window_5, + init_ff_sine_window_6, + init_ff_sine_window_7, + init_ff_sine_window_8, + init_ff_sine_window_9, + init_ff_sine_window_10, + init_ff_sine_window_11, + init_ff_sine_window_12, + init_ff_sine_window_13, +}; + +static AVOnce init_sine_window_once[9] = { + AV_ONCE_INIT, AV_ONCE_INIT, AV_ONCE_INIT, AV_ONCE_INIT, AV_ONCE_INIT, + AV_ONCE_INIT, AV_ONCE_INIT, AV_ONCE_INIT, AV_ONCE_INIT +}; +#endif + av_cold void AAC_RENAME(ff_init_ff_sine_windows)(int index) { assert(index >= 5 && index < FF_ARRAY_ELEMS(AAC_RENAME(ff_sine_windows))); #if !CONFIG_HARDCODED_TABLES +#ifdef BUILD_TABLES AAC_RENAME(ff_sine_window_init)(AAC_RENAME(ff_sine_windows)[index], 1 << index); +#else + ff_thread_once(&init_sine_window_once[index - 5], sine_window_init_func_array[index - 5]); +#endif #endif } diff --git a/libavcodec/sinewin_tablegen_template.c b/libavcodec/sinewin_tablegen_template.c index 43ce1ba82e..7c3c1d8af2 100644 --- a/libavcodec/sinewin_tablegen_template.c +++ b/libavcodec/sinewin_tablegen_template.c @@ -23,6 +23,7 @@ #include #include "libavcodec/aac_defines.h" #define CONFIG_HARDCODED_TABLES 0 +#define BUILD_TABLES #if USE_FIXED #define WRITE_FUNC write_int32_t_array