29 #ifndef _GLIBCXX_CONDITION_VARIABLE
30 #define _GLIBCXX_CONDITION_VARIABLE 1
32 #ifdef _GLIBCXX_SYSHDR
33 #pragma GCC system_header
38 #if __cplusplus < 201103L
47 #include <bits/shared_ptr.h>
50 #if __cplusplus > 201703L
54 #if defined(_GLIBCXX_HAS_GTHREADS)
56 namespace std _GLIBCXX_VISIBILITY(default)
58 _GLIBCXX_BEGIN_NAMESPACE_VERSION
76 #ifdef _GLIBCXX_USE_PTHREAD_COND_CLOCKWAIT
85 typedef __gthread_cond_t* native_handle_type;
94 notify_one() noexcept;
97 notify_all() noexcept;
102 template<
typename _Predicate>
110 #ifdef _GLIBCXX_USE_PTHREAD_COND_CLOCKWAIT
111 template<
typename _Duration>
115 {
return __wait_until_impl(__lock, __atime); }
118 template<
typename _Duration>
122 {
return __wait_until_impl(__lock, __atime); }
124 template<
typename _Clock,
typename _Duration>
129 #if __cplusplus > 201703L
130 static_assert(chrono::is_clock_v<_Clock>);
133 const typename _Clock::time_point __c_entry = _Clock::now();
135 const auto __delta = __atime - __c_entry;
136 const auto __s_atime = __s_entry +
137 chrono::__detail::ceil<__s_dur>(__delta);
139 if (__wait_until_impl(__lock, __s_atime) == cv_status::no_timeout)
140 return cv_status::no_timeout;
144 if (_Clock::now() < __atime)
145 return cv_status::no_timeout;
146 return cv_status::timeout;
149 template<
typename _Clock,
typename _Duration,
typename _Predicate>
156 if (wait_until(__lock, __atime) == cv_status::timeout)
161 template<
typename _Rep,
typename _Period>
167 return wait_until(__lock,
168 steady_clock::now() +
169 chrono::__detail::ceil<__dur>(__rtime));
172 template<
typename _Rep,
typename _Period,
typename _Predicate>
179 return wait_until(__lock,
180 steady_clock::now() +
181 chrono::__detail::ceil<__dur>(__rtime),
187 {
return _M_cond.native_handle(); }
190 #ifdef _GLIBCXX_USE_PTHREAD_COND_CLOCKWAIT
191 template<
typename _Dur>
196 __gthread_time_t __ts = chrono::__to_timeout_gthread_time_t(__atime);
197 _M_cond.wait_until(*__lock.mutex(), CLOCK_MONOTONIC, __ts);
199 return (steady_clock::now() < __atime
200 ? cv_status::no_timeout : cv_status::timeout);
204 template<
typename _Dur>
209 __gthread_time_t __ts = chrono::__to_timeout_gthread_time_t(__atime);
210 _M_cond.wait_until(*__lock.mutex(), __ts);
212 return (system_clock::now() < __atime
213 ? cv_status::no_timeout : cv_status::timeout);
220 struct __at_thread_exit_elt
222 __at_thread_exit_elt* _M_next;
223 void (*_M_cb)(
void*);
226 _GLIBCXX_BEGIN_INLINE_ABI_NAMESPACE(_V2)
232 #ifdef _GLIBCXX_USE_PTHREAD_COND_CLOCKWAIT
241 template<
typename _Lock>
244 explicit _Unlock(_Lock& __lk) : _M_lock(__lk) { __lk.unlock(); }
246 #pragma GCC diagnostic push
247 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
248 ~_Unlock() noexcept(
false)
255 { __throw_exception_again; }
262 #pragma GCC diagnostic pop
264 _Unlock(
const _Unlock&) =
delete;
265 _Unlock& operator=(
const _Unlock&) =
delete;
278 notify_one() noexcept
281 _M_cond.notify_one();
285 notify_all() noexcept
288 _M_cond.notify_all();
291 template<
typename _Lock>
297 _Unlock<_Lock> __unlock(__lock);
301 _M_cond.wait(__my_lock2);
305 template<
typename _Lock,
typename _Predicate>
307 wait(_Lock& __lock, _Predicate __p)
313 template<
typename _Lock,
typename _Clock,
typename _Duration>
315 wait_until(_Lock& __lock,
320 _Unlock<_Lock> __unlock(__lock);
324 return _M_cond.wait_until(__my_lock2, __atime);
327 template<
typename _Lock,
typename _Clock,
328 typename _Duration,
typename _Predicate>
330 wait_until(_Lock& __lock,
335 if (wait_until(__lock, __atime) == cv_status::timeout)
340 template<
typename _Lock,
typename _Rep,
typename _Period>
343 {
return wait_until(__lock, __clock_t::now() + __rtime); }
345 template<
typename _Lock,
typename _Rep,
346 typename _Period,
typename _Predicate>
348 wait_for(_Lock& __lock,
350 {
return wait_until(__lock, __clock_t::now() + __rtime,
std::move(__p)); }
352 #ifdef __glibcxx_jthread
353 template <
class _Lock,
class _Predicate>
354 bool wait(_Lock& __lock,
358 if (__stoken.stop_requested())
368 if (__stoken.stop_requested())
374 _Unlock<_Lock> __unlock(__lock);
376 _M_cond.wait(__my_lock2);
381 template <
class _Lock,
class _Clock,
class _Duration,
class _Predicate>
382 bool wait_until(_Lock& __lock,
387 if (__stoken.stop_requested())
399 if (__stoken.stop_requested())
403 _Unlock<_Lock> __u(__lock);
405 const auto __status = _M_cond.wait_until(__my_lock2, __abs_time);
406 __stop = (__status == std::cv_status::timeout) || __stoken.stop_requested();
416 template <
class _Lock,
class _Rep,
class _Period,
class _Predicate>
417 bool wait_for(_Lock& __lock,
422 auto __abst = std::chrono::steady_clock::now() + __rel_time;
423 return wait_until(__lock,
431 _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2)
434 _GLIBCXX_END_NAMESPACE_VERSION
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
bool uncaught_exception() noexcept
ISO C++ entities toplevel namespace is std.
Allow testing whether a stop request has been made on a stop_source.
A wrapper for callbacks to be run when a stop request is made.
chrono::duration represents a distance between two points in time
chrono::time_point represents a point in time as measured by a clock
Thrown as part of forced unwinding.
A smart pointer with reference-counted copy semantics.
A simple scoped lock type.
A movable scoped lock type.