From patchwork Tue Apr 26 19:15:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 53243 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 469D93858C2C for ; Tue, 26 Apr 2022 19:16:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 469D93858C2C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1651000593; bh=LWQzJm8IYoY2y5lHcl/c5t5u9p4VS8TpcoZyrJ4hT9o=; 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=vakIQ8HSZ/BTKMnobCh5YKBr4ET/uRqBJFP85AX/VRBXfWL2a6vjIXIx+JtnjcPrY eVcpbPRLGCQ2e9rxCafrCOO0DD+R3OlW6tevLW3XKrWzaqdBO2V0OgEpAcEaD12oNs 4YHl30wJAUdy7Jls3pHF3yec/inaxqYxmMrHBABk= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x329.google.com (mail-ot1-x329.google.com [IPv6:2607:f8b0:4864:20::329]) by sourceware.org (Postfix) with ESMTPS id 0FF6A385840C for ; Tue, 26 Apr 2022 19:15:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0FF6A385840C Received: by mail-ot1-x329.google.com with SMTP id i3-20020a056830010300b00605468119c3so13696426otp.11 for ; Tue, 26 Apr 2022 12:15:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LWQzJm8IYoY2y5lHcl/c5t5u9p4VS8TpcoZyrJ4hT9o=; b=dJJCW+2NWct/UCXBj0oGeOqZ1NwxnUhpth6HP2xhBsUNudl0KMOo/6j/duLVbAb+mX irXsqDclaK30Auz/A4RqUG//g8hJIYlgcoUUyA5KSjIoSlCWOlya3T4S40ETFpD85F0q u7hsUb59XiH1aQML47P+4zeIB3WlaX+mi9h256RCvQUdHNonWsi/lU0NqjE4LtiwUZIx NABw2NXpEjWlx59M+Rd/AhbZ+Jk4ElO5qwNvcfN8y2vrkEdeBAFd4rUneZQBML/KLzyT iBYrPBBrHosIqDp1BhGLjBynRXA6BSneQrggUi0e/q6TmNGPdZqr5qTTmI7rMNYhHVTy CuaQ== X-Gm-Message-State: AOAM532dVa+d6EfEVjNqkDzSCh2GEftxO1cPVA8e6iXa4yb1Ffjsetxi 0bAXZb8kN+3qu81iZEXcaQnOfjTThk7CRQ== X-Google-Smtp-Source: ABdhPJw7I4laImgPkSf4qiaQjtVtfkQ1BTbj0vDV2/ANRRaJXvUpniI8h/jhVChSdoStfRbBA3SX8A== X-Received: by 2002:a9d:4799:0:b0:605:6286:10d7 with SMTP id b25-20020a9d4799000000b00605628610d7mr8689015otf.75.1651000531950; Tue, 26 Apr 2022 12:15:31 -0700 (PDT) Received: from birita.. ([2804:431:c7ca:4214:745b:d03c:b667:123b]) by smtp.gmail.com with ESMTPSA id 123-20020a4a0181000000b00324a1217e96sm5884129oor.35.2022.04.26.12.15.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Apr 2022 12:15:31 -0700 (PDT) To: libc-alpha@sourceware.org, Florian Weimer Subject: [PATCH v2 2/4] Consolidate stdio-lock.h Date: Tue, 26 Apr 2022 16:15:21 -0300 Message-Id: <20220426191523.833171-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220426191523.833171-1-adhemerval.zanella@linaro.org> References: <20220426191523.833171-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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+patchwork=sourceware.org@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. The libc_malloc_debug is the only module that uses the __libc_lock_init_recursive directly in the code and it is kept to use the internal lock definitions. Checked on x86_64-linux-gnu and i686-linux-gnu. --- sysdeps/generic/stdio-lock.h | 21 +++----- sysdeps/htl/stdio-lock.h | 57 -------------------- sysdeps/nptl/libc-lock.h | 20 +++---- sysdeps/nptl/stdio-lock.h | 101 ----------------------------------- 4 files changed, 15 insertions(+), 184 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 14cf458bdd..fd61f0b5b7 100644 --- a/sysdeps/generic/stdio-lock.h +++ b/sysdeps/generic/stdio-lock.h @@ -45,20 +45,13 @@ __libc_lock_define_recursive (typedef, _IO_lock_t) #define _IO_cleanup_region_end(_doit) \ __libc_cleanup_region_end (_doit) -#if defined _LIBC && IS_IN (libc) - -# ifdef __EXCEPTIONS -# define _IO_acquire_lock(_fp) \ +#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 + _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 /* stdio-lock.h */ diff --git a/sysdeps/htl/stdio-lock.h b/sysdeps/htl/stdio-lock.h deleted file mode 100644 index c0a03c5a13..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-2022 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/libc-lock.h b/sysdeps/nptl/libc-lock.h index c186375c31..6c2d6acfd1 100644 --- a/sysdeps/nptl/libc-lock.h +++ b/sysdeps/nptl/libc-lock.h @@ -25,14 +25,10 @@ /* Mutex type. */ -#if defined _LIBC -# if (!IS_IN (libc) && !IS_IN (libpthread)) || !defined _LIBC +#if !IS_IN (libc) && !IS_IN (libc_malloc_debug) typedef struct { pthread_mutex_t mutex; } __libc_lock_recursive_t; -# else -typedef struct { int lock; int cnt; void *owner; } __libc_lock_recursive_t; -# endif #else -typedef struct __libc_lock_recursive_opaque__ __libc_lock_recursive_t; +typedef struct { int lock; int cnt; void *owner; } __libc_lock_recursive_t; #endif /* Define a lock variable NAME with storage class CLASS. The lock must be @@ -47,7 +43,7 @@ typedef struct __libc_lock_recursive_opaque__ __libc_lock_recursive_t; /* Define an initialized recursive lock variable NAME with storage class CLASS. */ -#if defined _LIBC && (IS_IN (libc) || IS_IN (libpthread)) +#if IS_IN (libc) || IS_IN (libc_malloc_debug) # define __libc_lock_define_initialized_recursive(CLASS, NAME) \ CLASS __libc_lock_recursive_t NAME = _LIBC_LOCK_RECURSIVE_INITIALIZER; # define _LIBC_LOCK_RECURSIVE_INITIALIZER \ @@ -60,7 +56,7 @@ typedef struct __libc_lock_recursive_opaque__ __libc_lock_recursive_t; #endif /* Initialize a recursive mutex. */ -#if defined _LIBC && (IS_IN (libc) || IS_IN (libpthread)) +#if IS_IN (libc) || IS_IN (libc_malloc_debug) # define __libc_lock_init_recursive(NAME) \ ((void) ((NAME) = (__libc_lock_recursive_t) _LIBC_LOCK_RECURSIVE_INITIALIZER)) #else @@ -78,7 +74,7 @@ typedef struct __libc_lock_recursive_opaque__ __libc_lock_recursive_t; #endif /* Finalize recursive named lock. */ -#if defined _LIBC && (IS_IN (libc) || IS_IN (libpthread)) +#if IS_IN (libc) || IS_IN (libc_malloc_debug) # define __libc_lock_fini_recursive(NAME) ((void) 0) #else # define __libc_lock_fini_recursive(NAME) \ @@ -86,7 +82,7 @@ typedef struct __libc_lock_recursive_opaque__ __libc_lock_recursive_t; #endif /* Lock the recursive named lock variable. */ -#if defined _LIBC && (IS_IN (libc) || IS_IN (libpthread)) +#if IS_IN (libc) || IS_IN (libc_malloc_debug) # define __libc_lock_lock_recursive(NAME) \ do { \ void *self = THREAD_SELF; \ @@ -103,7 +99,7 @@ typedef struct __libc_lock_recursive_opaque__ __libc_lock_recursive_t; #endif /* Try to lock the recursive named lock variable. */ -#if defined _LIBC && (IS_IN (libc) || IS_IN (libpthread)) +#if IS_IN (libc) || IS_IN (libc_malloc_debug) # define __libc_lock_trylock_recursive(NAME) \ ({ \ int result = 0; \ @@ -128,7 +124,7 @@ typedef struct __libc_lock_recursive_opaque__ __libc_lock_recursive_t; #endif /* Unlock the recursive named lock variable. */ -#if defined _LIBC && (IS_IN (libc) || IS_IN (libpthread)) +#if IS_IN (libc) || IS_IN (libc_malloc_debug) /* We do no error checking here. */ # define __libc_lock_unlock_recursive(NAME) \ do { \ diff --git a/sysdeps/nptl/stdio-lock.h b/sysdeps/nptl/stdio-lock.h deleted file mode 100644 index afa0b779c8..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-2022 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 */