]> 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>
Tue, 29 Apr 2025 17:25:59 +0000 (13:25 -0400)
commit6f5ba03968339122e11d5185fed5ff6f99ee4f28
tree3b97740818fc1b15445131ba21fed11ff2b7b9c7
parentd0da34ad302df61c4e4c3030845cbe9b986196bf
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