public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: DJ Delorie <dj@redhat.com>
To: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
Cc: libc-alpha@sourceware.org
Subject: Re: [PATCH] Use C11 atomics instead of atomic_decrement(_val)
Date: Thu, 08 Sep 2022 16:12:21 -0400	[thread overview]
Message-ID: <xnfsh139sq.fsf@greed.delorie.com> (raw)
In-Reply-To: <AS4PR08MB79012E086E6E43404D3CFFB683409@AS4PR08MB7901.eurprd08.prod.outlook.com>


atomic_decrement returns the NEW value
atomic_fetch_add_relaxed returns the OLD value

Wilco Dijkstra via Libc-alpha <libc-alpha@sourceware.org> writes:
> -  atomic_decrement (&__pthread_total);
> +  atomic_fetch_add_relaxed (&__pthread_total, -1);

Ok.

> -  atomic_decrement (&mp_.n_mmaps);
> +  atomic_fetch_add_relaxed (&mp_.n_mmaps, -1);

Ok.

> +++ b/manual/ipc.texi
> @@ -89,7 +89,7 @@ by @theglibc{}.
>  @c
>  @c Given the use atomic operations this function seems
>  @c to be AS-safe.  It is AC-unsafe because there is still
> -@c a window between atomic_decrement and the pthread_push
> +@c a window between atomic_fetch_add_relaxed and the pthread_push

Ok.

> +++ b/manual/llio.texi
> @@ -2569,7 +2569,7 @@ aiocb64}, since the LFS transparently replaces the old interface.
>  @c      lll_lock (pd->lock) @asulock @aculock
>  @c      atomic_fetch_add_relaxed ok
>  @c      clone ok
> -@c      atomic_decrement ok
> +@c      atomic_fetch_add_relaxed ok

Ok.

> -  if (atomic_decrement_val (&xidcmd->cntr) == 0)
> +  if (atomic_fetch_add_relaxed (&xidcmd->cntr, -1) == 1)

Ok.  See note at beginning for why ;-)

>        /* Oops, we lied for a second.  */
> -      atomic_decrement (&__nptl_nthreads);
> +      atomic_fetch_add_relaxed (&__nptl_nthreads, -1);

Ok.

> -      if (atomic_decrement_val (&map->counter) == 0)
> +      if (atomic_fetch_add_relaxed (&map->counter, -1) == 1)

Ok.

> -	  if (atomic_decrement_val (&mapped->counter) == 0)
> +	  if (atomic_fetch_add_relaxed (&mapped->counter, -1) == 1)

Ok.

> -	  if (atomic_decrement_val (&mapped->counter) == 0)
> +	  if (atomic_fetch_add_relaxed (&mapped->counter, -1) == 1)

Ok.

> -	  if (atomic_decrement_val (&mapped->counter) == 0)
> +	  if (atomic_fetch_add_relaxed (&mapped->counter, -1) == 1)

Ok.

> -	  if (atomic_decrement_val (&mapped->counter) == 0)
> +	  if (atomic_fetch_add_relaxed (&mapped->counter, -1) == 1)

Ok.

> -	  if (atomic_decrement_val (&mapped->counter) == 0)
> +	  if (atomic_fetch_add_relaxed (&mapped->counter, -1) == 1)

Ok.

> -  if (oldval != NULL && atomic_decrement_val (&oldval->counter) == 0)
> +  if (oldval != NULL && atomic_fetch_add_relaxed (&oldval->counter, -1) == 1)

Ok.

> -	  if (atomic_decrement_val (&mapped->counter) == 0)
> +	  if (atomic_fetch_add_relaxed (&mapped->counter, -1) == 1)

Ok.

> -	  if (atomic_decrement_val (&mapped->counter) == 0)
> +	  if (atomic_fetch_add_relaxed (&mapped->counter, -1) == 1)

Ok.

> -	  if (atomic_decrement_val (&mapped->counter) == 0)
> +	  if (atomic_fetch_add_relaxed (&mapped->counter, -1) == 1)

Ok.

LGTM.
Reviewed-by: DJ Delorie <dj@redhat.com>


  reply	other threads:[~2022-09-08 20:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-08 14:09 Wilco Dijkstra
2022-09-08 20:12 ` DJ Delorie [this message]
2022-09-09 14:02   ` Wilco Dijkstra

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=xnfsh139sq.fsf@greed.delorie.com \
    --to=dj@redhat.com \
    --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).