]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Optimize std::counting_semaphore for futex path
authorJonathan Wakely <jwakely@redhat.com>
Wed, 4 Jun 2025 14:53:20 +0000 (15:53 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Fri, 6 Jun 2025 08:52:31 +0000 (09:52 +0100)
commitbdae7824cd9a9d27665bf1b82f60a761a9745a6a
tree0c3f715c45a1c997fec090aa7218b3315a34e1b4
parent22f1f765db056527076a3b7e785b068f3ea28cf0
libstdc++: Optimize std::counting_semaphore for futex path

Rename __semaphore_base to __semaphore_impl, because it's not used as a
base class. Replace the three identical lambda expressions with a named
class, __semaphore_impl::_Available, which stores the most recent
value of the counter as a data member, and provides call operators that
test whether the value is decrementable (i.e. whether the semaphore can
be acquired).

Add a new __platform_semaphore_impl class template to be used when
__platform_wait is available, which uses __platform_wait_t for the
counter and uses more efficient atomic waits for the acquire functions.
For a binary semaphore some members are further optimized because we
know the counter can only be zero or one.

Also add a bare wait flag to __atomic_wait_address_v, for consistency
with __atomic_wait_address_until_v and __atomic_wait_address_for_v and
to allow semaphores to use it without the redundant overhead of tracking
waiters.

libstdc++-v3/ChangeLog:

* include/bits/atomic_wait.h (__atomic_wait_address_v): Add bare
wait flag.
* include/bits/semaphore_base.h (__semaphore_base): Rename to
__semaphore_impl. Replace local variable and predicate lambdas
with _Available struct.
(__platform_semaphore_impl): New class template.
(__semaphore_impl): Remove alias template.
(_Select_semaphore_impl): New alias template.
* include/std/semaphore (counting_semaphore): Use
_Select_semaphore_impl.
libstdc++-v3/include/bits/atomic_wait.h
libstdc++-v3/include/bits/semaphore_base.h
libstdc++-v3/include/std/semaphore