public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Andreas Schwab <schwab@linux-m68k.org>
To: Jangwoong Kim via Libc-alpha <libc-alpha@sourceware.org>
Cc: Jangwoong Kim <6812skiii@gmail.com>
Subject: Re: [PATCH v2] nptl: Effectively skip CAS in spinlock loop
Date: Tue, 14 Dec 2021 12:42:58 +0100	[thread overview]
Message-ID: <87wnk72z0d.fsf@igel.home> (raw)
In-Reply-To: <20211214110119.592-1-6812skiii@gmail.com> (Jangwoong Kim via Libc-alpha's message of "Tue, 14 Dec 2021 20:01:19 +0900")

On Dez 14 2021, Jangwoong Kim via Libc-alpha wrote:

> diff --git a/nptl/pthread_mutex_lock.c b/nptl/pthread_mutex_lock.c
> index 47b88a6b5b..3ad199a5e1 100644
> --- a/nptl/pthread_mutex_lock.c
> +++ b/nptl/pthread_mutex_lock.c
> @@ -138,7 +138,7 @@ PTHREAD_MUTEX_LOCK (pthread_mutex_t *mutex)
>  	  int cnt = 0;
>  	  int max_cnt = MIN (max_adaptive_count (),
>  			     mutex->__data.__spins * 2 + 10);
> -	  do
> +	  while (1)
>  	    {
>  	      if (cnt++ >= max_cnt)
>  		{
> @@ -146,10 +146,9 @@ PTHREAD_MUTEX_LOCK (pthread_mutex_t *mutex)
>  		  break;
>  		}
>  	      atomic_spin_nop ();
> -	      if (LLL_MUTEX_READ_LOCK (mutex) != 0)
> -		continue;
> +	      if (LLL_MUTEX_READ_LOCK (mutex) == 0 && LLL_MUTEX_TRYLOCK (mutex) == 0)
> +		break;
>  	    }
> -	  while (LLL_MUTEX_TRYLOCK (mutex) != 0);

You can keep the condition in the loop trailer.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

      reply	other threads:[~2021-12-14 11:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-14 11:01 Jangwoong Kim
2021-12-14 11:42 ` Andreas Schwab [this message]

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=87wnk72z0d.fsf@igel.home \
    --to=schwab@linux-m68k.org \
    --cc=6812skiii@gmail.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).