From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: libc-alpha@sourceware.org, Florian Weimer <fweimer@redhat.com>
Subject: [PATCH v2 2/4] Consolidate stdio-lock.h
Date: Tue, 26 Apr 2022 16:15:21 -0300 [thread overview]
Message-ID: <20220426191523.833171-3-adhemerval.zanella@linaro.org> (raw)
In-Reply-To: <20220426191523.833171-1-adhemerval.zanella@linaro.org>
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
- <https://www.gnu.org/licenses/>. */
-
-#ifndef _STDIO_LOCK_H
-#define _STDIO_LOCK_H 1
-
-#include <libc-lock.h>
-
-__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
- <https://www.gnu.org/licenses/>. */
-
-#ifndef _STDIO_LOCK_H
-#define _STDIO_LOCK_H 1
-
-#include <libc-lock.h>
-#include <lowlevellock.h>
-
-
-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 */
--
2.34.1
next prev parent reply other threads:[~2022-04-26 19:15 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-26 19:15 [PATCH v2 0/4] Move libio lock single-thread optimization to generic libc-lock Adhemerval Zanella
2022-04-26 19:15 ` [PATCH v2 1/4] libio: Assume _IO_MTSAFE_IO Adhemerval Zanella
2022-04-27 12:34 ` Florian Weimer
2022-04-27 18:40 ` Adhemerval Zanella
2022-04-27 19:35 ` Adhemerval Zanella
2022-04-26 19:15 ` Adhemerval Zanella [this message]
2022-04-27 13:25 ` [PATCH v2 2/4] Consolidate stdio-lock.h Florian Weimer
2022-04-27 16:15 ` Adhemerval Zanella
2022-04-27 18:00 ` Florian Weimer
2022-04-27 18:35 ` Adhemerval Zanella
2022-04-27 18:44 ` Florian Weimer
2022-04-27 18:49 ` Adhemerval Zanella
2022-04-26 19:15 ` [PATCH v2 3/4] Move libio lock single-thread optimization to generic libc-lock (BZ #27842) Adhemerval Zanella
2022-04-27 13:30 ` Florian Weimer
2022-04-27 16:32 ` Adhemerval Zanella
2022-04-28 16:39 ` Adhemerval Zanella
2022-04-28 16:56 ` Florian Weimer
2022-04-28 17:14 ` Adhemerval Zanella
2022-04-26 19:15 ` [PATCH v2 4/4] Assume _LIBC and libc module for libc-lock.h Adhemerval Zanella
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220426191523.833171-3-adhemerval.zanella@linaro.org \
--to=adhemerval.zanella@linaro.org \
--cc=fweimer@redhat.com \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).