diff mbox series

[3/4] Assume LLL_LOCK_INITIALIZER is 0

Message ID 20190222192703.18177-3-adhemerval.zanella@linaro.org
State New
Headers show
Series [1/4] Add single-thread.h header | expand

Commit Message

Adhemerval Zanella Netto Feb. 22, 2019, 7:27 p.m. UTC
Since hppa is not an outlier anymore regarding LLL_LOCK_INITIALIZER value,
we can now assume it 0 for all architectures.

Checked on a build for all major ABIs.

	* nptl/old_pthread_cond_broadcast.c (__pthread_cond_broadcast_2_0):
	Assume LLL_LOCK_INITIALIZER being 0.
	* nptl/old_pthread_cond_signal.c (__pthread_cond_signal_2_0): Likewise.
	* nptl/old_pthread_cond_timedwait.c (__pthread_cond_timedwait_2_0):
	Likewise.
	* nptl/old_pthread_cond_wait.c (__pthread_cond_wait_2_0): Likewise.
	* sysdeps/nptl/libc-lockP.h (__libc_lock_define_initialized): Likewise.
---
 nptl/old_pthread_cond_broadcast.c |  9 ---------
 nptl/old_pthread_cond_signal.c    |  9 ---------
 nptl/old_pthread_cond_timedwait.c |  9 ---------
 nptl/old_pthread_cond_wait.c      |  9 ---------
 sysdeps/nptl/libc-lockP.h         | 17 +++--------------
 5 files changed, 3 insertions(+), 50 deletions(-)

Comments

Adhemerval Zanella Netto April 9, 2019, 12:11 p.m. UTC | #1
Ping.

On 22/02/2019 16:27, Adhemerval Zanella wrote:
> Since hppa is not an outlier anymore regarding LLL_LOCK_INITIALIZER value,
> we can now assume it 0 for all architectures.
> 
> Checked on a build for all major ABIs.
> 
> 	* nptl/old_pthread_cond_broadcast.c (__pthread_cond_broadcast_2_0):
> 	Assume LLL_LOCK_INITIALIZER being 0.
> 	* nptl/old_pthread_cond_signal.c (__pthread_cond_signal_2_0): Likewise.
> 	* nptl/old_pthread_cond_timedwait.c (__pthread_cond_timedwait_2_0):
> 	Likewise.
> 	* nptl/old_pthread_cond_wait.c (__pthread_cond_wait_2_0): Likewise.
> 	* sysdeps/nptl/libc-lockP.h (__libc_lock_define_initialized): Likewise.
> ---
>  nptl/old_pthread_cond_broadcast.c |  9 ---------
>  nptl/old_pthread_cond_signal.c    |  9 ---------
>  nptl/old_pthread_cond_timedwait.c |  9 ---------
>  nptl/old_pthread_cond_wait.c      |  9 ---------
>  sysdeps/nptl/libc-lockP.h         | 17 +++--------------
>  5 files changed, 3 insertions(+), 50 deletions(-)
> 
> diff --git a/nptl/old_pthread_cond_broadcast.c b/nptl/old_pthread_cond_broadcast.c
> index f561eb941f..04f285a1b1 100644
> --- a/nptl/old_pthread_cond_broadcast.c
> +++ b/nptl/old_pthread_cond_broadcast.c
> @@ -31,18 +31,9 @@ __pthread_cond_broadcast_2_0 (pthread_cond_2_0_t *cond)
>      {
>        pthread_cond_t *newcond;
>  
> -#if LLL_LOCK_INITIALIZER == 0
>        newcond = (pthread_cond_t *) calloc (sizeof (pthread_cond_t), 1);
>        if (newcond == NULL)
>  	return ENOMEM;
> -#else
> -      newcond = (pthread_cond_t *) malloc (sizeof (pthread_cond_t));
> -      if (newcond == NULL)
> -	return ENOMEM;
> -
> -      /* Initialize the condvar.  */
> -      (void) pthread_cond_init (newcond, NULL);
> -#endif
>  
>        if (atomic_compare_and_exchange_bool_acq (&cond->cond, newcond, NULL))
>  	/* Somebody else just initialized the condvar.  */
> diff --git a/nptl/old_pthread_cond_signal.c b/nptl/old_pthread_cond_signal.c
> index a167c8addc..9b67cb8a54 100644
> --- a/nptl/old_pthread_cond_signal.c
> +++ b/nptl/old_pthread_cond_signal.c
> @@ -31,18 +31,9 @@ __pthread_cond_signal_2_0 (pthread_cond_2_0_t *cond)
>      {
>        pthread_cond_t *newcond;
>  
> -#if LLL_LOCK_INITIALIZER == 0
>        newcond = (pthread_cond_t *) calloc (sizeof (pthread_cond_t), 1);
>        if (newcond == NULL)
>  	return ENOMEM;
> -#else
> -      newcond = (pthread_cond_t *) malloc (sizeof (pthread_cond_t));
> -      if (newcond == NULL)
> -	return ENOMEM;
> -
> -      /* Initialize the condvar.  */
> -      (void) pthread_cond_init (newcond, NULL);
> -#endif
>  
>        if (atomic_compare_and_exchange_bool_acq (&cond->cond, newcond, NULL))
>  	/* Somebody else just initialized the condvar.  */
> diff --git a/nptl/old_pthread_cond_timedwait.c b/nptl/old_pthread_cond_timedwait.c
> index f920320b13..a1fde85825 100644
> --- a/nptl/old_pthread_cond_timedwait.c
> +++ b/nptl/old_pthread_cond_timedwait.c
> @@ -32,18 +32,9 @@ __pthread_cond_timedwait_2_0 (pthread_cond_2_0_t *cond, pthread_mutex_t *mutex,
>      {
>        pthread_cond_t *newcond;
>  
> -#if LLL_LOCK_INITIALIZER == 0
>        newcond = (pthread_cond_t *) calloc (sizeof (pthread_cond_t), 1);
>        if (newcond == NULL)
>  	return ENOMEM;
> -#else
> -      newcond = (pthread_cond_t *) malloc (sizeof (pthread_cond_t));
> -      if (newcond == NULL)
> -	return ENOMEM;
> -
> -      /* Initialize the condvar.  */
> -      (void) pthread_cond_init (newcond, NULL);
> -#endif
>  
>        if (atomic_compare_and_exchange_bool_acq (&cond->cond, newcond, NULL))
>  	/* Somebody else just initialized the condvar.  */
> diff --git a/nptl/old_pthread_cond_wait.c b/nptl/old_pthread_cond_wait.c
> index 2be41b36d6..bb65340a17 100644
> --- a/nptl/old_pthread_cond_wait.c
> +++ b/nptl/old_pthread_cond_wait.c
> @@ -31,18 +31,9 @@ __pthread_cond_wait_2_0 (pthread_cond_2_0_t *cond, pthread_mutex_t *mutex)
>      {
>        pthread_cond_t *newcond;
>  
> -#if LLL_LOCK_INITIALIZER == 0
>        newcond = (pthread_cond_t *) calloc (sizeof (pthread_cond_t), 1);
>        if (newcond == NULL)
>  	return ENOMEM;
> -#else
> -      newcond = (pthread_cond_t *) malloc (sizeof (pthread_cond_t));
> -      if (newcond == NULL)
> -	return ENOMEM;
> -
> -      /* Initialize the condvar.  */
> -      (void) pthread_cond_init (newcond, NULL);
> -#endif
>  
>        if (atomic_compare_and_exchange_bool_acq (&cond->cond, newcond, NULL))
>  	/* Somebody else just initialized the condvar.  */
> diff --git a/sysdeps/nptl/libc-lockP.h b/sysdeps/nptl/libc-lockP.h
> index fc1bfe57e5..07d583f11a 100644
> --- a/sysdeps/nptl/libc-lockP.h
> +++ b/sysdeps/nptl/libc-lockP.h
> @@ -71,23 +71,12 @@ typedef pthread_key_t __libc_key_t;
>     For the C library we take a deeper look at the initializer.  For
>     this implementation all fields are initialized to zero.  Therefore
>     we don't initialize the variable which allows putting it into the
> -   BSS section.  (Except on PA-RISC and other odd architectures, where
> -   initialized locks must be set to one due to the lack of normal
> -   atomic operations.) */
> +   BSS section.  */
>  
> +_Static_assert (LLL_LOCK_INITIALIZER == 0, "LLL_LOCK_INITIALIZER != 0");
>  #define _LIBC_LOCK_INITIALIZER LLL_LOCK_INITIALIZER
> -#if IS_IN (libc) || IS_IN (libpthread)
> -# if LLL_LOCK_INITIALIZER == 0
> -#  define __libc_lock_define_initialized(CLASS,NAME) \
> -  CLASS __libc_lock_t NAME;
> -# else
> -#  define __libc_lock_define_initialized(CLASS,NAME) \
> -  CLASS __libc_lock_t NAME = LLL_LOCK_INITIALIZER;
> -# endif
> -#else
> -# define __libc_lock_define_initialized(CLASS,NAME) \
> +#define __libc_lock_define_initialized(CLASS,NAME) \
>    CLASS __libc_lock_t NAME;
> -#endif
>  
>  #define __libc_rwlock_define_initialized(CLASS,NAME) \
>    CLASS __libc_rwlock_t NAME = PTHREAD_RWLOCK_INITIALIZER;
>
Yann Droneaud April 29, 2019, 9:38 a.m. UTC | #2
Le vendredi 22 février 2019 à 16:27 -0300, Adhemerval Zanella a écrit :
> Since hppa is not an outlier anymore regarding LLL_LOCK_INITIALIZER value,
> we can now assume it 0 for all architectures.
> 
> Checked on a build for all major ABIs.
> 
> 	* nptl/old_pthread_cond_broadcast.c (__pthread_cond_broadcast_2_0):
> 	Assume LLL_LOCK_INITIALIZER being 0.
> 	* nptl/old_pthread_cond_signal.c (__pthread_cond_signal_2_0): Likewise.
> 	* nptl/old_pthread_cond_timedwait.c (__pthread_cond_timedwait_2_0):
> 	Likewise.
> 	* nptl/old_pthread_cond_wait.c (__pthread_cond_wait_2_0): Likewise.
> 	* sysdeps/nptl/libc-lockP.h (__libc_lock_define_initialized): Likewise.
> ---
>  nptl/old_pthread_cond_broadcast.c |  9 ---------
>  nptl/old_pthread_cond_signal.c    |  9 ---------
>  nptl/old_pthread_cond_timedwait.c |  9 ---------
>  nptl/old_pthread_cond_wait.c      |  9 ---------
>  sysdeps/nptl/libc-lockP.h         | 17 +++--------------
>  5 files changed, 3 insertions(+), 50 deletions(-)
> 
> 

Proposed changes are fine for me.

If LLL_LOCK_INITIALIZER is known to be 0 the following statement in 
__pthread_initialize_minimal_internal() from nptl/nptl-init.c could be
removed:

  if (LLL_LOCK_INITIALIZER != 0)
    THREAD_SETMEM (pd, lock, LLL_LOCK_INITIALIZER);

Regards.
Adhemerval Zanella Netto April 29, 2019, 12:13 p.m. UTC | #3
On 29/04/2019 06:38, Yann Droneaud wrote:
> Le vendredi 22 février 2019 à 16:27 -0300, Adhemerval Zanella a écrit :
>> Since hppa is not an outlier anymore regarding LLL_LOCK_INITIALIZER value,
>> we can now assume it 0 for all architectures.
>>
>> Checked on a build for all major ABIs.
>>
>> 	* nptl/old_pthread_cond_broadcast.c (__pthread_cond_broadcast_2_0):
>> 	Assume LLL_LOCK_INITIALIZER being 0.
>> 	* nptl/old_pthread_cond_signal.c (__pthread_cond_signal_2_0): Likewise.
>> 	* nptl/old_pthread_cond_timedwait.c (__pthread_cond_timedwait_2_0):
>> 	Likewise.
>> 	* nptl/old_pthread_cond_wait.c (__pthread_cond_wait_2_0): Likewise.
>> 	* sysdeps/nptl/libc-lockP.h (__libc_lock_define_initialized): Likewise.
>> ---
>>  nptl/old_pthread_cond_broadcast.c |  9 ---------
>>  nptl/old_pthread_cond_signal.c    |  9 ---------
>>  nptl/old_pthread_cond_timedwait.c |  9 ---------
>>  nptl/old_pthread_cond_wait.c      |  9 ---------
>>  sysdeps/nptl/libc-lockP.h         | 17 +++--------------
>>  5 files changed, 3 insertions(+), 50 deletions(-)
>>
>>
> 
> Proposed changes are fine for me.
> 
> If LLL_LOCK_INITIALIZER is known to be 0 the following statement in 
> __pthread_initialize_minimal_internal() from nptl/nptl-init.c could be
> removed:
> 
>   if (LLL_LOCK_INITIALIZER != 0)
>     THREAD_SETMEM (pd, lock, LLL_LOCK_INITIALIZER);
> 
> Regards.
> 

Indeed, I have added it on my local branch. Thanks for checking on this.
diff mbox series

Patch

diff --git a/nptl/old_pthread_cond_broadcast.c b/nptl/old_pthread_cond_broadcast.c
index f561eb941f..04f285a1b1 100644
--- a/nptl/old_pthread_cond_broadcast.c
+++ b/nptl/old_pthread_cond_broadcast.c
@@ -31,18 +31,9 @@  __pthread_cond_broadcast_2_0 (pthread_cond_2_0_t *cond)
     {
       pthread_cond_t *newcond;
 
-#if LLL_LOCK_INITIALIZER == 0
       newcond = (pthread_cond_t *) calloc (sizeof (pthread_cond_t), 1);
       if (newcond == NULL)
 	return ENOMEM;
-#else
-      newcond = (pthread_cond_t *) malloc (sizeof (pthread_cond_t));
-      if (newcond == NULL)
-	return ENOMEM;
-
-      /* Initialize the condvar.  */
-      (void) pthread_cond_init (newcond, NULL);
-#endif
 
       if (atomic_compare_and_exchange_bool_acq (&cond->cond, newcond, NULL))
 	/* Somebody else just initialized the condvar.  */
diff --git a/nptl/old_pthread_cond_signal.c b/nptl/old_pthread_cond_signal.c
index a167c8addc..9b67cb8a54 100644
--- a/nptl/old_pthread_cond_signal.c
+++ b/nptl/old_pthread_cond_signal.c
@@ -31,18 +31,9 @@  __pthread_cond_signal_2_0 (pthread_cond_2_0_t *cond)
     {
       pthread_cond_t *newcond;
 
-#if LLL_LOCK_INITIALIZER == 0
       newcond = (pthread_cond_t *) calloc (sizeof (pthread_cond_t), 1);
       if (newcond == NULL)
 	return ENOMEM;
-#else
-      newcond = (pthread_cond_t *) malloc (sizeof (pthread_cond_t));
-      if (newcond == NULL)
-	return ENOMEM;
-
-      /* Initialize the condvar.  */
-      (void) pthread_cond_init (newcond, NULL);
-#endif
 
       if (atomic_compare_and_exchange_bool_acq (&cond->cond, newcond, NULL))
 	/* Somebody else just initialized the condvar.  */
diff --git a/nptl/old_pthread_cond_timedwait.c b/nptl/old_pthread_cond_timedwait.c
index f920320b13..a1fde85825 100644
--- a/nptl/old_pthread_cond_timedwait.c
+++ b/nptl/old_pthread_cond_timedwait.c
@@ -32,18 +32,9 @@  __pthread_cond_timedwait_2_0 (pthread_cond_2_0_t *cond, pthread_mutex_t *mutex,
     {
       pthread_cond_t *newcond;
 
-#if LLL_LOCK_INITIALIZER == 0
       newcond = (pthread_cond_t *) calloc (sizeof (pthread_cond_t), 1);
       if (newcond == NULL)
 	return ENOMEM;
-#else
-      newcond = (pthread_cond_t *) malloc (sizeof (pthread_cond_t));
-      if (newcond == NULL)
-	return ENOMEM;
-
-      /* Initialize the condvar.  */
-      (void) pthread_cond_init (newcond, NULL);
-#endif
 
       if (atomic_compare_and_exchange_bool_acq (&cond->cond, newcond, NULL))
 	/* Somebody else just initialized the condvar.  */
diff --git a/nptl/old_pthread_cond_wait.c b/nptl/old_pthread_cond_wait.c
index 2be41b36d6..bb65340a17 100644
--- a/nptl/old_pthread_cond_wait.c
+++ b/nptl/old_pthread_cond_wait.c
@@ -31,18 +31,9 @@  __pthread_cond_wait_2_0 (pthread_cond_2_0_t *cond, pthread_mutex_t *mutex)
     {
       pthread_cond_t *newcond;
 
-#if LLL_LOCK_INITIALIZER == 0
       newcond = (pthread_cond_t *) calloc (sizeof (pthread_cond_t), 1);
       if (newcond == NULL)
 	return ENOMEM;
-#else
-      newcond = (pthread_cond_t *) malloc (sizeof (pthread_cond_t));
-      if (newcond == NULL)
-	return ENOMEM;
-
-      /* Initialize the condvar.  */
-      (void) pthread_cond_init (newcond, NULL);
-#endif
 
       if (atomic_compare_and_exchange_bool_acq (&cond->cond, newcond, NULL))
 	/* Somebody else just initialized the condvar.  */
diff --git a/sysdeps/nptl/libc-lockP.h b/sysdeps/nptl/libc-lockP.h
index fc1bfe57e5..07d583f11a 100644
--- a/sysdeps/nptl/libc-lockP.h
+++ b/sysdeps/nptl/libc-lockP.h
@@ -71,23 +71,12 @@  typedef pthread_key_t __libc_key_t;
    For the C library we take a deeper look at the initializer.  For
    this implementation all fields are initialized to zero.  Therefore
    we don't initialize the variable which allows putting it into the
-   BSS section.  (Except on PA-RISC and other odd architectures, where
-   initialized locks must be set to one due to the lack of normal
-   atomic operations.) */
+   BSS section.  */
 
+_Static_assert (LLL_LOCK_INITIALIZER == 0, "LLL_LOCK_INITIALIZER != 0");
 #define _LIBC_LOCK_INITIALIZER LLL_LOCK_INITIALIZER
-#if IS_IN (libc) || IS_IN (libpthread)
-# if LLL_LOCK_INITIALIZER == 0
-#  define __libc_lock_define_initialized(CLASS,NAME) \
-  CLASS __libc_lock_t NAME;
-# else
-#  define __libc_lock_define_initialized(CLASS,NAME) \
-  CLASS __libc_lock_t NAME = LLL_LOCK_INITIALIZER;
-# endif
-#else
-# define __libc_lock_define_initialized(CLASS,NAME) \
+#define __libc_lock_define_initialized(CLASS,NAME) \
   CLASS __libc_lock_t NAME;
-#endif
 
 #define __libc_rwlock_define_initialized(CLASS,NAME) \
   CLASS __libc_rwlock_t NAME = PTHREAD_RWLOCK_INITIALIZER;