]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Refactor loops in std::__platform_semaphore
authorJonathan Wakely <jwakely@redhat.com>
Mon, 2 Sep 2024 11:29:04 +0000 (12:29 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Sat, 14 Sep 2024 12:46:30 +0000 (13:46 +0100)
commit01670a4095791733e0389acead832e3da757c9d7
tree73655a8f306a480ffbe7dcde016eafadccaedf8f
parent49cb7150f0e93e8332f4b78753675b255a5c58f2
libstdc++: Refactor loops in std::__platform_semaphore

Refactor the loops to all use the same form, and to not need explicit
'break' or 'continue' jumps. This also avoids a -Wunused-variable
warning with -Wsystem-headers.

Also fix a bug for absolute timeouts specified with a time that isn't
implicitly convertible to __clock_t::time_point, e.g. one with a higher
resolution such as picoseconds. Use chrono::ceil to round up to the next
time point representable by the clock.

libstdc++-v3/ChangeLog:

* include/bits/semaphore_base.h (__platform_semaphore): Refactor
loops to all use similar forms.
(__platform_semaphore::_M_try_acquire_until): Use chrono::ceil
to explicitly convert to __clock_t::time_point.
* testsuite/30_threads/semaphore/try_acquire_for.cc: Check that
using a very high resolution timeout compiles.
* testsuite/30_threads/semaphore/platform_try_acquire_for.cc:
New test.
libstdc++-v3/include/bits/semaphore_base.h
libstdc++-v3/testsuite/30_threads/semaphore/platform_try_acquire_for.cc [new file with mode: 0644]
libstdc++-v3/testsuite/30_threads/semaphore/try_acquire_for.cc