From patchwork Thu May 27 20:44:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 43619 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CB1A8395C82F; Thu, 27 May 2021 20:45:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CB1A8395C82F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1622148309; bh=h/Uq4PjxsRE6Z6oA8DFL13NFNwDs2IDWjxff6PA1dQk=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=kXHLFiZT9ChJJK+TF2j8O17RD2ixpLvCN9N5uyvLgUnn3qGzW6gUvcaCnwS4sEQns MKPNIDT3W0qn0DEAIvGTiO705fQZS76s4r+q2pZuzlC0tjZ5kQ3+wq6HOwEqdPUjLH vUL2fF8S6UCgiNJ4bVzzwIuPXAHIF/yhWkhg6Y6o= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qv1-xf2c.google.com (mail-qv1-xf2c.google.com [IPv6:2607:f8b0:4864:20::f2c]) by sourceware.org (Postfix) with ESMTPS id 64FFB395C82F for ; Thu, 27 May 2021 20:45:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 64FFB395C82F Received: by mail-qv1-xf2c.google.com with SMTP id ez19so843592qvb.3 for ; Thu, 27 May 2021 13:45:06 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=h/Uq4PjxsRE6Z6oA8DFL13NFNwDs2IDWjxff6PA1dQk=; b=Z213V4yNc2MN7Gx84ngB2NCdkv85E5UBYoaaczT6skNHV5V1yaZo6uz3Tk0Au6AUCv q93CFdiAJ/ABSrHf/JT/Uikfw8muj5gW2IQU+w0+I+d5NIttVSZi9/tpIavqRvVh+mjO qn9vBnre2iyMYHqNodJrbr/JqDZRLzuwlGvQjwAq2ya6tZ5SP83rfa9xqRKMLT2VOOv0 AHcFa7ITMfvX3+Sux4ZOTrc95VwgeyxAUpkPenSc0sQB1cVzlIBL4b/SSvKy94/JZUxZ e1TyuOAUBkDf/p8WCWSJozBcPL/Z52NlMZaBVV7bEG54beXXgNSQrKM7wDNGSYwpuCuo P3nQ== X-Gm-Message-State: AOAM531cUQDzUdYgTxX5ZERRsLh/a6YXCv1LAW2VYljIEhaRDbmTg5qs HWU9wsY/P821s2vzN50WptcRwQ6NF2ktXw== X-Google-Smtp-Source: ABdhPJzXy7fZRalow2hnfu/uOUbWNze6+roEfTkKEyjicHhvaus1zY0jZH3QBLKabHFK2/I52EA+wg== X-Received: by 2002:a0c:ec04:: with SMTP id y4mr432983qvo.51.1622148305743; Thu, 27 May 2021 13:45:05 -0700 (PDT) Received: from birita.. ([177.194.37.86]) by smtp.googlemail.com with ESMTPSA id e14sm2058385qkl.1.2021.05.27.13.45.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 May 2021 13:45:05 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH 3/4] Consolidate stdio-lock.h Date: Thu, 27 May 2021 17:44:56 -0300 Message-Id: <20210527204457.1250196-4-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210527204457.1250196-1-adhemerval.zanella@linaro.org> References: <20210527204457.1250196-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" The NPTL replicate the sysdeps/nptl/libc-lock.h recursive lock. Use the Hurd one as generic one, which already uses the __libc_lock functions. Checked on x86_64-linux-gnu and i686-linux-gnu. --- sysdeps/generic/stdio-lock.h | 15 +++--- sysdeps/htl/stdio-lock.h | 57 -------------------- sysdeps/nptl/stdio-lock.h | 101 ----------------------------------- 3 files changed, 6 insertions(+), 167 deletions(-) delete mode 100644 sysdeps/htl/stdio-lock.h delete mode 100644 sysdeps/nptl/stdio-lock.h diff --git a/sysdeps/generic/stdio-lock.h b/sysdeps/generic/stdio-lock.h index c17b8383d9..a900275400 100644 --- a/sysdeps/generic/stdio-lock.h +++ b/sysdeps/generic/stdio-lock.h @@ -47,17 +47,14 @@ __libc_lock_define_recursive (typedef, _IO_lock_t) #if defined _LIBC && IS_IN (libc) -# ifdef __EXCEPTIONS # define _IO_acquire_lock(_fp) \ do { \ - FILE *_IO_acquire_lock_file \ - __attribute__((cleanup (_IO_acquire_lock_fct))) \ - = (_fp); \ - _IO_flockfile (_IO_acquire_lock_file); -# else -# define _IO_acquire_lock(_fp) _IO_acquire_lock_needs_exceptions_enabled -# endif -# define _IO_release_lock(_fp) ; } while (0) + _IO_cleanup_region_start((void (*) (void *)) &_IO_funlockfile, _fp); \ + _IO_flockfile (_fp); +# define _IO_release_lock(_fp) \ + _IO_funlockfile (_fp); \ + _IO_cleanup_region_end (0); \ + } while (0) #endif diff --git a/sysdeps/htl/stdio-lock.h b/sysdeps/htl/stdio-lock.h deleted file mode 100644 index 59969de45d..0000000000 --- a/sysdeps/htl/stdio-lock.h +++ /dev/null @@ -1,57 +0,0 @@ -/* Thread package specific definitions of stream lock type. Hurd version. - Copyright (C) 2000-2021 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#ifndef _STDIO_LOCK_H -#define _STDIO_LOCK_H 1 - -#include - -__libc_lock_define_recursive (typedef, _IO_lock_t) -#define _IO_lock_t_defined 1 - -/* We need recursive (counting) mutexes. */ -# define _IO_lock_initializer _LIBC_LOCK_RECURSIVE_INITIALIZER - -#define _IO_lock_init(_name) __libc_lock_init_recursive (_name) -#define _IO_lock_fini(_name) __libc_lock_fini_recursive (_name) -#define _IO_lock_lock(_name) __libc_lock_lock_recursive (_name) -#define _IO_lock_trylock(_name) __libc_lock_trylock_recursive (_name) -#define _IO_lock_unlock(_name) __libc_lock_unlock_recursive (_name) - - -#define _IO_cleanup_region_start(_fct, _fp) \ - __libc_cleanup_region_start (((_fp)->_flags & _IO_USER_LOCK) == 0, _fct, _fp) -#define _IO_cleanup_region_start_noarg(_fct) \ - __libc_cleanup_region_start (1, _fct, NULL) -#define _IO_cleanup_region_end(_doit) \ - __libc_cleanup_region_end (_doit) - -#if defined _LIBC && IS_IN (libc) - -# define _IO_acquire_lock(_fp) \ - do { \ - _IO_cleanup_region_start((void (*) (void *)) &_IO_funlockfile, _fp); \ - _IO_flockfile (_fp); -# define _IO_release_lock(_fp) \ - _IO_funlockfile (_fp); \ - _IO_cleanup_region_end (0); \ - } while (0) - -#endif - -#endif /* stdio-lock.h */ diff --git a/sysdeps/nptl/stdio-lock.h b/sysdeps/nptl/stdio-lock.h deleted file mode 100644 index a4f419b516..0000000000 --- a/sysdeps/nptl/stdio-lock.h +++ /dev/null @@ -1,101 +0,0 @@ -/* Thread package specific definitions of stream lock type. NPTL version. - Copyright (C) 2000-2021 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#ifndef _STDIO_LOCK_H -#define _STDIO_LOCK_H 1 - -#include -#include - - -typedef struct { int lock; int cnt; void *owner; } _IO_lock_t; -#define _IO_lock_t_defined 1 - -#define _IO_lock_initializer { LLL_LOCK_INITIALIZER, 0, NULL } - -#define _IO_lock_init(_name) \ - ((void) ((_name) = (_IO_lock_t) _IO_lock_initializer)) - -#define _IO_lock_fini(_name) \ - ((void) 0) - -#define _IO_lock_lock(_name) \ - do { \ - void *__self = THREAD_SELF; \ - if ((_name).owner != __self) \ - { \ - lll_lock ((_name).lock, LLL_PRIVATE); \ - (_name).owner = __self; \ - } \ - ++(_name).cnt; \ - } while (0) - -#define _IO_lock_trylock(_name) \ - ({ \ - int __result = 0; \ - void *__self = THREAD_SELF; \ - if ((_name).owner != __self) \ - { \ - if (lll_trylock ((_name).lock) == 0) \ - { \ - (_name).owner = __self; \ - (_name).cnt = 1; \ - } \ - else \ - __result = EBUSY; \ - } \ - else \ - ++(_name).cnt; \ - __result; \ - }) - -#define _IO_lock_unlock(_name) \ - do { \ - if (--(_name).cnt == 0) \ - { \ - (_name).owner = NULL; \ - lll_unlock ((_name).lock, LLL_PRIVATE); \ - } \ - } while (0) - - - -#define _IO_cleanup_region_start(_fct, _fp) \ - __libc_cleanup_region_start (((_fp)->_flags & _IO_USER_LOCK) == 0, _fct, _fp) -#define _IO_cleanup_region_start_noarg(_fct) \ - __libc_cleanup_region_start (1, _fct, NULL) -#define _IO_cleanup_region_end(_doit) \ - __libc_cleanup_region_end (_doit) - -#if defined _LIBC && IS_IN (libc) - -# ifdef __EXCEPTIONS -# define _IO_acquire_lock(_fp) \ - do { \ - FILE *_IO_acquire_lock_file \ - __attribute__((cleanup (_IO_acquire_lock_fct))) \ - = (_fp); \ - _IO_flockfile (_IO_acquire_lock_file); -# else -# define _IO_acquire_lock(_fp) _IO_acquire_lock_needs_exceptions_enabled -# endif -# define _IO_release_lock(_fp) ; } while (0) - -#endif - -#endif /* stdio-lock.h */