]> git.ipfire.org Git - thirdparty/gcc.git/commit - libstdc++-v3/testsuite/30_threads/lock/4.cc
libstdc++: Simplify std::try_lock and std::lock further
authorJonathan Wakely <jwakely@redhat.com>
Tue, 22 Jun 2021 12:35:19 +0000 (13:35 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Tue, 22 Jun 2021 20:17:25 +0000 (21:17 +0100)
commitc556596119307f9ef1c9079ef2bd3a035dea355d
tree0292d6d165df8828a851fe18b32cf4f2698dc3c0
parentb5a29741db11007e37d8d4ff977b89a8314abfda
libstdc++: Simplify std::try_lock and std::lock further

The std::try_lock and std::lock algorithms can use iteration instead of
recursion when all lockables have the same type and can be held by an
array of unique_lock<L> objects.

By making this change to __detail::__try_lock_impl it also benefits
__detail::__lock_impl, which uses it. For std::lock we can just put the
iterative version directly in std::lock, to avoid making any call to
__detail::__lock_impl.

Signed-off-by: Matthias Kretz <m.kretz@gsi.de>
Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
Co-authored-by: Matthias Kretz <m.kretz@gsi.de>
libstdc++-v3/ChangeLog:

* include/std/mutex (lock): Replace recursion with iteration
when lockables all have the same type.
(__detail::__try_lock_impl): Likewise. Pass lockables as
parameters, instead of a tuple. Always lock the first one, and
recurse for the rest.
(__detail::__lock_impl): Adjust call to __try_lock_impl.
(__detail::__try_to_lock): Remove.
* testsuite/30_threads/lock/3.cc: Check that mutexes are locked.
* testsuite/30_threads/lock/4.cc: Also test non-heterogeneous
arguments.
* testsuite/30_threads/unique_lock/cons/60497.cc: Also check
std::try_lock.
* testsuite/30_threads/try_lock/5.cc: New test.
libstdc++-v3/include/std/mutex
libstdc++-v3/testsuite/30_threads/lock/3.cc
libstdc++-v3/testsuite/30_threads/lock/4.cc
libstdc++-v3/testsuite/30_threads/try_lock/5.cc [new file with mode: 0644]
libstdc++-v3/testsuite/30_threads/unique_lock/cons/60497.cc