]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Rewrite std::counting_semaphore base class [PR118494]
authorJonathan Wakely <jwakely@redhat.com>
Wed, 15 Jan 2025 09:05:28 +0000 (09:05 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Fri, 30 May 2025 09:02:29 +0000 (10:02 +0100)
commit3e9fff1b7f9a31e6bc635880b09cbc32f8be353d
tree27e93ad09b883634c539d00df3922d149fc3fe42
parent42fc1e9712c8e0d929b23009095c6e14b32fda93
libstdc++: Rewrite std::counting_semaphore base class [PR118494]

Remove __platform_semaphore. Replace __atomic_semaphore with
__semaphore_base<bool> and change its counter to be ptrdiff_t when the
count doesn't fit in __platform_wait_t (PR 118494).

Make the std::counting_semaphore constructor constexpr to support
constant initialization (PR 110854).

Add precondition checks to the constructor and release member functions
(PR 98749).

libstdc++-v3/ChangeLog:

PR libstdc++/118494
PR libstdc++/110854
PR libstdc++/98749
* acinclude.m4 (GLIBCXX_CHECK_GTHREADS): Remove checks for
sem_timedwait. Do not define _GLIBCXX_HAVE_POSIX_SEMAPHORE.
* config.h.in: Regenerate.
* configure: Regenerate.
* include/bits/semaphore_base.h (__platform_semaphore): Remove.
(__atomic_semaphore): Replace with __semaphore_base<bool> and
make type of _M_count depend on template parameter. Fix _S_max
constant to use correct type.
(__semaphore_base::_M_try_acquire): Qualify to avoid ADL.
(__semaphore_base::_M_release): Return old value. Remove FIXME
comment.
(__semaphore_impl): Replace typedef with alias template.
* include/bits/version.def (semaphore): Do not depend on
_GLIBCXX_HAVE_POSIX_SEMAPHORE.
* include/bits/version.h: Regenerate.
* include/std/semaphore (semaphore): Adjust type of _M_sem
member. Add constexpr to constructor. Add assertions to
(semaphore::semaphore(ptrdiff_t)): Add constexpr. Add assertion
for precondition.
(semaphore::release): Add assertion using value returned from
_M_release.
* testsuite/30_threads/semaphore/100806.cc: Increase template
argument for std::counting_semaphore, so constructor
precondition is met.
* testsuite/30_threads/semaphore/cons.cc: New test.
* testsuite/30_threads/semaphore/try_acquire_posix.cc: Remove.
* testsuite/30_threads/semaphore/platform_try_acquire_for.cc:
Removed.
libstdc++-v3/acinclude.m4
libstdc++-v3/config.h.in
libstdc++-v3/configure
libstdc++-v3/include/bits/semaphore_base.h
libstdc++-v3/include/bits/version.def
libstdc++-v3/include/bits/version.h
libstdc++-v3/include/std/semaphore
libstdc++-v3/testsuite/30_threads/semaphore/100806.cc
libstdc++-v3/testsuite/30_threads/semaphore/cons.cc [new file with mode: 0644]
libstdc++-v3/testsuite/30_threads/semaphore/platform_try_acquire_for.cc [deleted file]
libstdc++-v3/testsuite/30_threads/semaphore/try_acquire_posix.cc [deleted file]