]> 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>
Fri, 17 Jan 2025 19:56:58 +0000 (14:56 -0500)
commit4f7b051f8ee3feff1b53b27a906f245afaa9cee1
tree1fc44b4ef01b9a323b2cadddee5065ae35d43838
parentb42cc6af11062c260c7dfa91f1c89891366fed3e
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>
nptl/pthread_cond_wait.c