29#ifndef _GLIBCXX_CONDITION_VARIABLE
30#define _GLIBCXX_CONDITION_VARIABLE 1
32#pragma GCC system_header
36#if __cplusplus < 201103L
44#include <bits/shared_ptr.h>
47#if __cplusplus > 201703L
51#if defined(_GLIBCXX_HAS_GTHREADS)
53namespace std _GLIBCXX_VISIBILITY(default)
55_GLIBCXX_BEGIN_NAMESPACE_VERSION
73#ifdef _GLIBCXX_USE_PTHREAD_COND_CLOCKWAIT
82 typedef __gthread_cond_t* native_handle_type;
91 notify_one()
noexcept;
94 notify_all()
noexcept;
99 template<
typename _Predicate>
107#ifdef _GLIBCXX_USE_PTHREAD_COND_CLOCKWAIT
108 template<
typename _Duration>
112 {
return __wait_until_impl(__lock, __atime); }
115 template<
typename _Duration>
119 {
return __wait_until_impl(__lock, __atime); }
121 template<
typename _Clock,
typename _Duration>
126#if __cplusplus > 201703L
127 static_assert(chrono::is_clock_v<_Clock>);
130 const typename _Clock::time_point __c_entry = _Clock::now();
132 const auto __delta = __atime - __c_entry;
133 const auto __s_atime = __s_entry +
134 chrono::__detail::ceil<__s_dur>(__delta);
136 if (__wait_until_impl(__lock, __s_atime) == cv_status::no_timeout)
137 return cv_status::no_timeout;
141 if (_Clock::now() < __atime)
142 return cv_status::no_timeout;
143 return cv_status::timeout;
146 template<
typename _Clock,
typename _Duration,
typename _Predicate>
153 if (wait_until(__lock, __atime) == cv_status::timeout)
158 template<
typename _Rep,
typename _Period>
164 return wait_until(__lock,
165 steady_clock::now() +
166 chrono::__detail::ceil<__dur>(__rtime));
169 template<
typename _Rep,
typename _Period,
typename _Predicate>
176 return wait_until(__lock,
177 steady_clock::now() +
178 chrono::__detail::ceil<__dur>(__rtime),
184 {
return _M_cond.native_handle(); }
187#ifdef _GLIBCXX_USE_PTHREAD_COND_CLOCKWAIT
188 template<
typename _Dur>
193 auto __s = chrono::time_point_cast<chrono::seconds>(__atime);
194 auto __ns = chrono::duration_cast<chrono::nanoseconds>(__atime - __s);
196 __gthread_time_t __ts =
198 static_cast<std::time_t
>(__s.time_since_epoch().count()),
199 static_cast<long>(__ns.count())
202 _M_cond.wait_until(*__lock.mutex(), CLOCK_MONOTONIC, __ts);
204 return (steady_clock::now() < __atime
205 ? cv_status::no_timeout : cv_status::timeout);
209 template<
typename _Dur>
214 auto __s = chrono::time_point_cast<chrono::seconds>(__atime);
215 auto __ns = chrono::duration_cast<chrono::nanoseconds>(__atime - __s);
217 __gthread_time_t __ts =
219 static_cast<std::time_t
>(__s.time_since_epoch().count()),
220 static_cast<long>(__ns.count())
223 _M_cond.wait_until(*__lock.mutex(), __ts);
225 return (system_clock::now() < __atime
226 ? cv_status::no_timeout : cv_status::timeout);
233 struct __at_thread_exit_elt
235 __at_thread_exit_elt* _M_next;
236 void (*_M_cb)(
void*);
239_GLIBCXX_BEGIN_INLINE_ABI_NAMESPACE(_V2)
245#ifdef _GLIBCXX_USE_PTHREAD_COND_CLOCKWAIT
254 template<
typename _Lock>
257 explicit _Unlock(_Lock& __lk) : _M_lock(__lk) { __lk.unlock(); }
259#pragma GCC diagnostic push
260#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
261 ~_Unlock()
noexcept(
false)
268 { __throw_exception_again; }
275#pragma GCC diagnostic pop
277 _Unlock(
const _Unlock&) =
delete;
278 _Unlock& operator=(
const _Unlock&) =
delete;
291 notify_one()
noexcept
294 _M_cond.notify_one();
298 notify_all()
noexcept
301 _M_cond.notify_all();
304 template<
typename _Lock>
310 _Unlock<_Lock> __unlock(__lock);
314 _M_cond.wait(__my_lock2);
318 template<
typename _Lock,
typename _Predicate>
320 wait(_Lock& __lock, _Predicate __p)
326 template<
typename _Lock,
typename _Clock,
typename _Duration>
328 wait_until(_Lock& __lock,
333 _Unlock<_Lock> __unlock(__lock);
337 return _M_cond.wait_until(__my_lock2, __atime);
340 template<
typename _Lock,
typename _Clock,
341 typename _Duration,
typename _Predicate>
343 wait_until(_Lock& __lock,
348 if (wait_until(__lock, __atime) == cv_status::timeout)
353 template<
typename _Lock,
typename _Rep,
typename _Period>
356 {
return wait_until(__lock, __clock_t::now() + __rtime); }
358 template<
typename _Lock,
typename _Rep,
359 typename _Period,
typename _Predicate>
361 wait_for(_Lock& __lock,
363 {
return wait_until(__lock, __clock_t::now() + __rtime,
std::move(__p)); }
365#ifdef __cpp_lib_jthread
366 template <
class _Lock,
class _Predicate>
367 bool wait(_Lock& __lock,
371 if (__stoken.stop_requested())
381 if (__stoken.stop_requested())
387 _Unlock<_Lock> __unlock(__lock);
389 _M_cond.wait(__my_lock2);
394 template <
class _Lock,
class _Clock,
class _Duration,
class _Predicate>
395 bool wait_until(_Lock& __lock,
400 if (__stoken.stop_requested())
412 if (__stoken.stop_requested())
416 _Unlock<_Lock> __u(__lock);
418 const auto __status = _M_cond.wait_until(__my_lock2, __abs_time);
419 __stop = (__status == std::cv_status::timeout) || __stoken.stop_requested();
429 template <
class _Lock,
class _Rep,
class _Period,
class _Predicate>
430 bool wait_for(_Lock& __lock,
435 auto __abst = std::chrono::steady_clock::now() + __rel_time;
436 return wait_until(__lock,
444_GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2)
447_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.