]> git.ipfire.org Git - thirdparty/glibc.git/commit
nptl: Remove unnecessary quadruple check in pthread_cond_wait
authorMalte Skarupke <malteskarupke@fastmail.fm>
Wed, 4 Dec 2024 12:56:13 +0000 (07:56 -0500)
committerCarlos O'Donell <carlos@redhat.com>
Mon, 28 Apr 2025 16:51:44 +0000 (12:51 -0400)
commit2a259b6d77dc5bdab5c8f4ee0e69572d5699d4bf
treec36bb7579c9e020983dc47b74e16d3c2c03da0a1
parent136a29f9d0a3924828d5a16be82d054637517c95
nptl: Remove unnecessary quadruple check in pthread_cond_wait

pthread_cond_wait was checking whether it was in a closed group no less than
four times. Checking once is enough. Here are the four checks:

1. While spin-waiting. This was dead code: maxspin is set to 0 and has been
   for years.
2. Before deciding to go to sleep, and before incrementing grefs: I kept this
3. After incrementing grefs. There is no reason to think that the group would
   close while we do an atomic increment. Obviously it could close at any
   point, but that doesn't mean we have to recheck after every step. This
   check was equally good as check 2, except it has to do more work.
4. When we find ourselves in a group that has a signal. We only get here after
   we check that we're not in a closed group. There is no need to check again.
   The check would only have helped in cases where the compare_exchange in the
   next line would also have failed. Relying on the compare_exchange is fine.

Removing the duplicate checks clarifies the code.

Signed-off-by: Malte Skarupke <malteskarupke@fastmail.fm>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
(cherry picked from commit 4f7b051f8ee3feff1b53b27a906f245afaa9cee1)
nptl/pthread_cond_wait.c