30#ifndef _GLIBCXX_ATOMIC_TIMED_WAIT_H
31#define _GLIBCXX_ATOMIC_TIMED_WAIT_H 1
34#pragma GCC system_header
39#if __glibcxx_atomic_wait
43#ifdef _GLIBCXX_HAVE_LINUX_FUTEX
47namespace std _GLIBCXX_VISIBILITY(default)
49_GLIBCXX_BEGIN_NAMESPACE_VERSION
53 using __wait_clock_t = chrono::steady_clock;
55 template<
typename _Clock,
typename _Dur>
56 __wait_clock_t::time_point
57 __to_wait_clock(
const chrono::time_point<_Clock, _Dur>& __atime)
noexcept
59 const typename _Clock::time_point __c_entry = _Clock::now();
60 const __wait_clock_t::time_point __w_entry = __wait_clock_t::now();
61 const auto __delta = __atime - __c_entry;
62 using __w_dur =
typename __wait_clock_t::duration;
66 template<
typename _Dur>
67 __wait_clock_t::time_point
68 __to_wait_clock(
const chrono::time_point<__wait_clock_t,
69 _Dur>& __atime)
noexcept
71 using __w_dur =
typename __wait_clock_t::duration;
72 if constexpr (is_same_v<__w_dur, _Dur>)
79 __wait_until_impl(
const void* __addr, __wait_args_base& __args,
80 const __wait_clock_t::duration& __atime);
82 template<
typename _Clock,
typename _Dur>
84 __wait_until(
const void* __addr, __wait_args_base& __args,
85 const chrono::time_point<_Clock, _Dur>& __atime)
noexcept
87 auto __at = __detail::__to_wait_clock(__atime);
88 auto __res = __detail::__wait_until_impl(__addr, __args,
89 __at.time_since_epoch());
91 if constexpr (!is_same_v<__wait_clock_t, _Clock>)
97 if (_Clock::now() < __atime)
98 __res._M_timeout =
false;
103 template<
typename _Rep,
typename _Period>
105 __wait_for(
const void* __addr, __wait_args_base& __args,
106 const chrono::duration<_Rep, _Period>& __rtime)
noexcept
108 if (!__rtime.count())
111 __args._M_flags |= __wait_flags::__do_spin | __wait_flags::__spin_only;
112 return __detail::__wait_impl(__addr, __args);
116 auto const __atime = chrono::steady_clock::now() + __reltime;
117 return __detail::__wait_until(__addr, __args, __atime);
122 template<
typename _Tp,
123 typename _Pred,
typename _ValFn,
124 typename _Clock,
typename _Dur>
126 __atomic_wait_address_until(
const _Tp* __addr, _Pred&& __pred,
129 bool __bare_wait =
false) noexcept
131 __detail::__wait_args __args{ __addr, __bare_wait };
132 _Tp __val = __args._M_setup_wait(__addr, __vfn);
133 while (!__pred(__val))
135 auto __res = __detail::__wait_until(__addr, __args, __atime);
136 if (__res._M_timeout)
138 __val = __args._M_setup_wait(__addr, __vfn, __res);
143 template<
typename _Clock,
typename _Dur>
145 __atomic_wait_address_until_v(
const __detail::__platform_wait_t* __addr,
146 __detail::__platform_wait_t __old,
149 bool __bare_wait =
false) noexcept
152 __glibcxx_assert(__platform_wait_uses_type<__detail::__platform_wait_t>);
154 __detail::__wait_args __args{ __addr, __old, __order, __bare_wait };
155 auto __res = __detail::__wait_until(__addr, __args, __atime);
156 return !__res._M_timeout;
159 template<
typename _Tp,
typename _ValFn,
160 typename _Clock,
typename _Dur>
162 __atomic_wait_address_until_v(
const _Tp* __addr, _Tp&& __old,
165 bool __bare_wait =
false) noexcept
167 auto __pfn = [&](
const _Tp& __val) {
168 return !__detail::__atomic_eq(__old, __val);
170 return std::__atomic_wait_address_until(__addr, __pfn, __vfn, __atime,
174 template<
typename _Tp,
175 typename _Pred,
typename _ValFn,
176 typename _Rep,
typename _Period>
178 __atomic_wait_address_for(
const _Tp* __addr, _Pred&& __pred,
181 bool __bare_wait =
false) noexcept
183 __detail::__wait_args __args{ __addr, __bare_wait };
184 _Tp __val = __args._M_setup_wait(__addr, __vfn);
185 while (!__pred(__val))
187 auto __res = __detail::__wait_for(__addr, __args, __rtime);
188 if (__res._M_timeout)
190 __val = __args._M_setup_wait(__addr, __vfn);
195 template<
typename _Rep,
typename _Period>
197 __atomic_wait_address_for_v(
const __detail::__platform_wait_t* __addr,
198 __detail::__platform_wait_t __old,
201 bool __bare_wait =
false) noexcept
204 __glibcxx_assert(__platform_wait_uses_type<__detail::__platform_wait_t>);
206 __detail::__wait_args __args{ __addr, __old, __order, __bare_wait };
207 auto __res = __detail::__wait_for(__addr, __args, __rtime);
208 return !__res._M_timeout;
211 template<
typename _Tp,
typename _ValFn,
212 typename _Rep,
typename _Period>
214 __atomic_wait_address_for_v(
const _Tp* __addr, _Tp&& __old, _ValFn&& __vfn,
216 bool __bare_wait =
false) noexcept
218 auto __pfn = [&](
const _Tp& __val) {
219 return !__detail::__atomic_eq(__old, __val);
221 return __atomic_wait_address_for(__addr, __pfn,
forward<_ValFn>(__vfn),
222 __rtime, __bare_wait);
224_GLIBCXX_END_NAMESPACE_VERSION
constexpr __enable_if_is_duration< _ToDur > ceil(const duration< _Rep, _Period > &__d)
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
ISO C++ entities toplevel namespace is std.
Implementation details not part of the namespace std interface.
chrono::duration represents a distance between two points in time
chrono::time_point represents a point in time as measured by a clock