public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
To: Wilco Dijkstra <Wilco.Dijkstra@arm.com>,
	'GNU C Library' <libc-alpha@sourceware.org>
Subject: Re: [PATCH] Use C11 atomics instead of atomic_and/or
Date: Wed, 21 Sep 2022 14:08:57 -0300	[thread overview]
Message-ID: <32dd1e65-c065-99fa-4c49-d0612f1ef9e3@linaro.org> (raw)
In-Reply-To: <AS4PR08MB79017C4FC5AE484617FAC654837F9@AS4PR08MB7901.eurprd08.prod.outlook.com>



On 05/09/22 13:48, Wilco Dijkstra wrote:
> Remove the 4 uses of atomic_and and atomic_or with atomic_fetch_and_acquire and
> atomic_fetch_or_acquire
> 
> Passes regress on AArch64.

LGTM, the current atomic_or and atomic_and have acquire semantic already.  What
I am not not sure if if we need to use release MO on start_thread, since the
idea is to synchronize with the locking on pthread_mutex_lock.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

> 
> ---
> 
> diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c
> index d206ed7bf4c2305c0d65bc2a47baefe02969e3d2..d802c67b059af390e122e82f09e886d0c8950fd7 100644
> --- a/nptl/pthread_create.c
> +++ b/nptl/pthread_create.c
> @@ -539,7 +539,7 @@ start_thread (void *arg)
>  # endif
>  	  this->__list.__next = NULL;
>  
> -	  atomic_or (&this->__lock, FUTEX_OWNER_DIED);
> +	  atomic_fetch_or_acquire (&this->__lock, FUTEX_OWNER_DIED);
>  	  futex_wake ((unsigned int *) &this->__lock, 1,
>  		      /* XYZ */ FUTEX_SHARED);
>  	}
> diff --git a/nptl/pthread_mutex_lock.c b/nptl/pthread_mutex_lock.c
> index 6e767a87247063c0ac84242ef13e72af79021104..439b1e6391c50d5922dec6c48e7f2a2a632a89d9 100644
> --- a/nptl/pthread_mutex_lock.c
> +++ b/nptl/pthread_mutex_lock.c
> @@ -462,7 +462,7 @@ __pthread_mutex_lock_full (pthread_mutex_t *mutex)
>  
>  	if (__glibc_unlikely (oldval & FUTEX_OWNER_DIED))
>  	  {
> -	    atomic_and (&mutex->__data.__lock, ~FUTEX_OWNER_DIED);
> +	    atomic_fetch_and_acquire (&mutex->__data.__lock, ~FUTEX_OWNER_DIED);
>  
>  	    /* We got the mutex.  */
>  	    mutex->__data.__count = 1;
> diff --git a/nptl/pthread_mutex_timedlock.c b/nptl/pthread_mutex_timedlock.c
> index 0fcaabfb482546fd6f1f9cc4b13edc82f6e6796c..af70a60528cb101c8e52d4165950ee0d11f6f895 100644
> --- a/nptl/pthread_mutex_timedlock.c
> +++ b/nptl/pthread_mutex_timedlock.c
> @@ -392,7 +392,7 @@ __pthread_mutex_clocklock_common (pthread_mutex_t *mutex,
>  
>  	if (__glibc_unlikely (oldval & FUTEX_OWNER_DIED))
>  	  {
> -	    atomic_and (&mutex->__data.__lock, ~FUTEX_OWNER_DIED);
> +	    atomic_fetch_and_acquire (&mutex->__data.__lock, ~FUTEX_OWNER_DIED);
>  
>  	    /* We got the mutex.  */
>  	    mutex->__data.__count = 1;
> diff --git a/nptl/pthread_mutex_trylock.c b/nptl/pthread_mutex_trylock.c
> index 8a7de8e598803f606899fe1c9b8775bc24dd14ec..50524942a76c753ce4add20c35dfe7f659a1908b 100644
> --- a/nptl/pthread_mutex_trylock.c
> +++ b/nptl/pthread_mutex_trylock.c
> @@ -308,7 +308,7 @@ ___pthread_mutex_trylock (pthread_mutex_t *mutex)
>  
>  	if (__glibc_unlikely (oldval & FUTEX_OWNER_DIED))
>  	  {
> -	    atomic_and (&mutex->__data.__lock, ~FUTEX_OWNER_DIED);
> +	    atomic_fetch_and_acquire (&mutex->__data.__lock, ~FUTEX_OWNER_DIED);
>  
>  	    /* We got the mutex.  */
>  	    mutex->__data.__count = 1;
> 

  reply	other threads:[~2022-09-21 17:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-05 16:48 Wilco Dijkstra
2022-09-21 17:08 ` Adhemerval Zanella Netto [this message]
2022-09-22 14:06   ` Wilco Dijkstra
2022-09-23 13:34     ` Adhemerval Zanella Netto

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=32dd1e65-c065-99fa-4c49-d0612f1ef9e3@linaro.org \
    --to=adhemerval.zanella@linaro.org \
    --cc=Wilco.Dijkstra@arm.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).