]> git.ipfire.org Git - thirdparty/glibc.git/commit
nptl: Remove unnecessary quadruple check in pthread_cond_wait
authorMalte Skarupke <malteskarupke@fastmail.fm>
Fri, 11 Jul 2025 12:57:44 +0000 (05:57 -0700)
committerCarlos O'Donell <carlos@redhat.com>
Fri, 11 Jul 2025 17:55:25 +0000 (13:55 -0400)
commit44eaf0615d3feddfb0a0a0bb20adff2119dd44c4
tree542358171ea7dc37f3d5d4322f6de124209def3d
parent1fa5e5189713e64fbd1bd775ab1cb6de1035eff9
nptl: Remove unnecessary quadruple check in pthread_cond_wait

[BZ #25847]

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.

(cherry picked from commit 4f7b051f8ee3feff1b53b27a906f245afaa9cee1)

Signed-off-by: Sunil Dora <sunilkumar.dora@windriver.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
nptl/pthread_cond_wait.c