diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2020-03-25 22:07:02 +0000 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2020-03-25 22:07:02 +0000 |
commit | bf1fc37bb4a3cab851e2acec811427d5243a22e9 (patch) | |
tree | baa9ab1b47e7c91a5a682057b4e89197c3bd7feb /libstdc++-v3/include/std/shared_mutex | |
parent | fe4b53b2e7e58d3bcf476a0a319b51a5a8c668a2 (diff) | |
download | gcc-bf1fc37bb4a3cab851e2acec811427d5243a22e9.zip gcc-bf1fc37bb4a3cab851e2acec811427d5243a22e9.tar.gz gcc-bf1fc37bb4a3cab851e2acec811427d5243a22e9.tar.bz2 |
libstdc++: Define and use chrono::is_clock for C++20
For C++20 the wait_until members of mutexes and condition variables are
required to be ill-formed if given a clock that doesn't meet the
requirements for a clock type. To implement that requirement this patch
adds static assertions using the chrono::is_clock trait, and defines
that trait.
To avoid expensive checks for the common cases, the trait (and
associated variable template) are explicitly specialized for the
standard clock types.
This also moves the filesystem::__file_clock type from <filesystem> to
<chrono>, so that chrono::file_clock and chrono::file_time can be
defined in <chrono> as required.
* include/bits/fs_fwd.h (filesystem::__file_clock): Move to ...
* include/std/chrono (filesystem::__file_clock): Here.
(filesystem::__file_clock::from_sys, filesystem::__file_clock::to_sys):
Define public member functions for C++20.
(is_clock, is_clock_v): Define traits for C++20.
* include/std/condition_variable (condition_variable::wait_until): Add
check for valid clock.
* include/std/future (_State_baseV2::wait_until): Likewise.
* include/std/mutex (__timed_mutex_impl::_M_try_lock_until): Likewise.
* include/std/shared_mutex (shared_timed_mutex::try_lock_shared_until):
Likewise.
* include/std/thread (this_thread::sleep_until): Likewise.
* testsuite/30_threads/condition_variable/members/2.cc: Qualify
slow_clock with new namespace.
* testsuite/30_threads/condition_variable/members/clock_neg.cc: New
test.
* testsuite/30_threads/condition_variable_any/members/clock_neg.cc:
New test.
* testsuite/30_threads/future/members/clock_neg.cc: New test.
* testsuite/30_threads/recursive_timed_mutex/try_lock_until/3.cc:
Qualify slow_clock with new namespace.
* testsuite/30_threads/recursive_timed_mutex/try_lock_until/
clock_neg.cc: New test.
* testsuite/30_threads/shared_future/members/clock_neg.cc: New
test.
* testsuite/30_threads/shared_lock/locking/clock_neg.cc: New test.
* testsuite/30_threads/shared_timed_mutex/try_lock_until/clock_neg.cc:
New test.
* testsuite/30_threads/timed_mutex/try_lock_until/3.cc: Qualify
slow_clock with new namespace.
* testsuite/30_threads/timed_mutex/try_lock_until/4.cc: Likewise.
* testsuite/30_threads/timed_mutex/try_lock_until/clock_neg.cc: New
test.
* testsuite/30_threads/unique_lock/locking/clock_neg.cc: New test.
* testsuite/std/time/traits/is_clock.cc: New test.
* testsuite/util/slow_clock.h (slow_clock): Move to __gnu_test
namespace.
Diffstat (limited to 'libstdc++-v3/include/std/shared_mutex')
-rw-r--r-- | libstdc++-v3/include/std/shared_mutex | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/libstdc++-v3/include/std/shared_mutex b/libstdc++-v3/include/std/shared_mutex index 9b597e7..414dce3 100644 --- a/libstdc++-v3/include/std/shared_mutex +++ b/libstdc++-v3/include/std/shared_mutex @@ -554,6 +554,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION bool try_lock_until(const chrono::time_point<_Clock, _Duration>& __atime) { +#if __cplusplus > 201703L + static_assert(chrono::is_clock_v<_Clock>); +#endif // The user-supplied clock may not tick at the same rate as // steady_clock, so we must loop in order to guarantee that // the timeout has expired before returning false. @@ -639,6 +642,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION try_lock_shared_until(const chrono::time_point<_Clock, _Duration>& __atime) { +#if __cplusplus > 201703L + static_assert(chrono::is_clock_v<_Clock>); +#endif // The user-supplied clock may not tick at the same rate as // steady_clock, so we must loop in order to guarantee that // the timeout has expired before returning false. |