[v2,4/4] Assume _LIBC and libc module for libc-lock.h

Message ID 20220426191523.833171-5-adhemerval.zanella@linaro.org
State Superseded
Headers
Series Move libio lock single-thread optimization to generic libc-lock |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent
dj/TryBot-32bit success Build for i686

Commit Message

Adhemerval Zanella Netto April 26, 2022, 7:15 p.m. UTC
  The libc-lock.h is not used outside glibc nor with modules different
than libc or libc_malloc_debug.

Checked on x86_64-linux-gnu.
---
 sysdeps/mach/libc-lock.h |  9 ------
 sysdeps/nptl/libc-lock.h | 67 ++++++----------------------------------
 2 files changed, 10 insertions(+), 66 deletions(-)
  

Patch

diff --git a/sysdeps/mach/libc-lock.h b/sysdeps/mach/libc-lock.h
index ee38948d1e..bb1a492fa9 100644
--- a/sysdeps/mach/libc-lock.h
+++ b/sysdeps/mach/libc-lock.h
@@ -19,8 +19,6 @@ 
 #ifndef _LIBC_LOCK_H
 #define _LIBC_LOCK_H 1
 
-#ifdef _LIBC
-
 #include <tls.h>
 #include <lowlevellock.h>
 
@@ -38,11 +36,6 @@  extern char __libc_lock_self0[0];
 #define __libc_lock_owner_self()   \
   (__LIBC_NO_TLS () ? (void *)&__libc_lock_self0 : THREAD_SELF)
 
-#else
-typedef struct __libc_lock_opaque__ __libc_lock_t;
-typedef struct __libc_lock_recursive_opaque__ __libc_lock_recursive_t;
-#endif
-
 /* Define a lock variable NAME with storage class CLASS.  The lock must be
    initialized with __libc_lock_init before it can be used (or define it
    with __libc_lock_define_initialized, below).  Use `extern' for CLASS to
@@ -215,7 +208,6 @@  struct __libc_once
 /* Get once control variable.  */
 #define __libc_once_get(ONCE_CONTROL)	((ONCE_CONTROL).done != 0)
 
-#ifdef _LIBC
 /* We need portable names for some functions.  E.g., when they are
    used as argument to __libc_cleanup_region_start.  */
 #define __libc_mutex_unlock __libc_lock_unlock
@@ -223,6 +215,5 @@  struct __libc_once
 /* Hide the definitions which are only supposed to be used inside libc in
    a separate file.  This file is not present in the installation!  */
 # include <libc-lockP.h>
-#endif
 
 #endif	/* libc-lock.h */
diff --git a/sysdeps/nptl/libc-lock.h b/sysdeps/nptl/libc-lock.h
index abd84e71b4..5c85a250d7 100644
--- a/sysdeps/nptl/libc-lock.h
+++ b/sysdeps/nptl/libc-lock.h
@@ -25,11 +25,7 @@ 
 
 
 /* Mutex type.  */
-#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
 
 /* Define a lock variable NAME with storage class CLASS.  The lock must be
    initialized with __libc_lock_init before it can be used (or define it
@@ -43,68 +39,36 @@  typedef struct { int lock; int cnt; void *owner; } __libc_lock_recursive_t;
 
 /* Define an initialized recursive lock variable NAME with storage
    class CLASS.  */
-#if IS_IN (libc) || IS_IN (libc_malloc_debug)
-# define __libc_lock_define_initialized_recursive(CLASS, NAME) \
+#define __libc_lock_define_initialized_recursive(CLASS, NAME) \
   CLASS __libc_lock_recursive_t NAME = _LIBC_LOCK_RECURSIVE_INITIALIZER;
-# define _LIBC_LOCK_RECURSIVE_INITIALIZER \
+#define _LIBC_LOCK_RECURSIVE_INITIALIZER \
   { LLL_LOCK_INITIALIZER, 0, NULL }
-#else
-# define __libc_lock_define_initialized_recursive(CLASS,NAME) \
-  CLASS __libc_lock_recursive_t NAME = _LIBC_LOCK_RECURSIVE_INITIALIZER;
-# define _LIBC_LOCK_RECURSIVE_INITIALIZER \
-  {PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP}
-#endif
 
 /* Initialize a recursive mutex.  */
-#if IS_IN (libc) || IS_IN (libc_malloc_debug)
-# define __libc_lock_init_recursive(NAME) \
+#define __libc_lock_init_recursive(NAME) \
   ((void) ((NAME) = (__libc_lock_recursive_t) _LIBC_LOCK_RECURSIVE_INITIALIZER))
-#else
-# define __libc_lock_init_recursive(NAME) \
-  do {									      \
-    if (__pthread_mutex_init != NULL)					      \
-      {									      \
-	pthread_mutexattr_t __attr;					      \
-	__pthread_mutexattr_init (&__attr);				      \
-	__pthread_mutexattr_settype (&__attr, PTHREAD_MUTEX_RECURSIVE_NP);    \
-	__pthread_mutex_init (&(NAME).mutex, &__attr);			      \
-	__pthread_mutexattr_destroy (&__attr);				      \
-      }									      \
-  } while (0)
-#endif
 
 /* Finalize recursive named lock.  */
-#if IS_IN (libc) || IS_IN (libc_malloc_debug)
-# define __libc_lock_fini_recursive(NAME) ((void) 0)
-#else
-# define __libc_lock_fini_recursive(NAME) \
-  __libc_maybe_call (__pthread_mutex_destroy, (&(NAME).mutex), 0)
-#endif
+#define __libc_lock_fini_recursive(NAME) ((void) 0)
 
 /* Lock the recursive named lock variable.  */
-#if IS_IN (libc) || IS_IN (libc_malloc_debug)
-# define __libc_lock_lock_recursive(NAME) \
+#define __libc_lock_lock_recursive(NAME) \
   do {									      \
     void *self = THREAD_SELF;						      \
-    if (!SINGLE_THREAD_P && (NAME).owner != self)						      \
+    if (!SINGLE_THREAD_P && (NAME).owner != self)			      \
       {									      \
 	lll_lock ((NAME).lock, LLL_PRIVATE);				      \
 	(NAME).owner = self;						      \
       }									      \
     ++(NAME).cnt;							      \
   } while (0)
-#else
-# define __libc_lock_lock_recursive(NAME) \
-  __libc_maybe_call (__pthread_mutex_lock, (&(NAME).mutex), 0)
-#endif
 
 /* Try to lock the recursive named lock variable.  */
-#if IS_IN (libc) || IS_IN (libc_malloc_debug)
-# define __libc_lock_trylock_recursive(NAME) \
+#define __libc_lock_trylock_recursive(NAME) \
   ({									      \
     int result = 0;							      \
     void *self = THREAD_SELF;						      \
-    if (!SINGLE_THREAD_P && (NAME).owner != self)						      \
+    if (!SINGLE_THREAD_P && (NAME).owner != self)			      \
       {									      \
 	if (lll_trylock ((NAME).lock) == 0)				      \
 	  {								      \
@@ -118,15 +82,10 @@  typedef struct { int lock; int cnt; void *owner; } __libc_lock_recursive_t;
       ++(NAME).cnt;							      \
     result;								      \
   })
-#else
-# define __libc_lock_trylock_recursive(NAME) \
-  __libc_maybe_call (__pthread_mutex_trylock, (&(NAME).mutex), 0)
-#endif
 
 /* Unlock the recursive named lock variable.  */
-#if IS_IN (libc) || IS_IN (libc_malloc_debug)
 /* We do no error checking here.  */
-# define __libc_lock_unlock_recursive(NAME) \
+#define __libc_lock_unlock_recursive(NAME) \
   do {									      \
     if (--(NAME).cnt == 0)						      \
       {									      \
@@ -135,10 +94,6 @@  typedef struct { int lock; int cnt; void *owner; } __libc_lock_recursive_t;
 	  lll_unlock ((NAME).lock, LLL_PRIVATE);			      \
       }									      \
   } while (0)
-#else
-# define __libc_lock_unlock_recursive(NAME) \
-  __libc_maybe_call (__pthread_mutex_unlock, (&(NAME).mutex), 0)
-#endif
 
 /* Put the unwind buffer BUFFER on the per-thread callback stack.  The
    caller must fill BUFFER->__routine and BUFFER->__arg before calling
@@ -178,8 +133,6 @@  libc_hidden_proto (__libc_cleanup_pop_restore)
 
 /* Hide the definitions which are only supposed to be used inside libc in
    a separate file.  This file is not present in the installation!  */
-#ifdef _LIBC
-# include "libc-lockP.h"
-#endif
+#include "libc-lockP.h"
 
 #endif	/* libc-lock.h */