72 class condition_variable
76#ifdef _GLIBCXX_USE_PTHREAD_COND_CLOCKWAIT
77 using __clock_t = steady_clock;
79 using __clock_t = system_clock;
85 typedef __gthread_cond_t* native_handle_type;
87 condition_variable()
noexcept;
88 ~condition_variable()
noexcept;
90 condition_variable(
const condition_variable&) =
delete;
91 condition_variable& operator=(
const condition_variable&) =
delete;
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>);
132 using __s_dur =
typename __clock_t::duration;
133 const typename _Clock::time_point __c_entry = _Clock::now();
134 const __clock_t::time_point __s_entry = __clock_t::now();
135 const auto __delta = __atime - __c_entry;
136 const auto __s_atime = __s_entry +
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>
168 using __dur =
typename steady_clock::duration;
169 return wait_until(__lock,
170 steady_clock::now() +
174 template<
typename _Rep,
typename _Period,
typename _Predicate>
180 using __dur =
typename steady_clock::duration;
181 return wait_until(__lock,
182 steady_clock::now() +
189 {
return _M_cond.native_handle(); }
192#ifdef _GLIBCXX_USE_PTHREAD_COND_CLOCKWAIT
193 template<
typename _Dur>
198 __gthread_time_t __ts = chrono::__to_timeout_gthread_time_t(__atime);
199 _M_cond.wait_until(*__lock.mutex(), CLOCK_MONOTONIC, __ts);
201 return (steady_clock::now() < __atime
202 ? cv_status::no_timeout : cv_status::timeout);
206 template<
typename _Dur>
211 __gthread_time_t __ts = chrono::__to_timeout_gthread_time_t(__atime);
212 _M_cond.wait_until(*__lock.mutex(), __ts);
214 return (system_clock::now() < __atime
215 ? cv_status::no_timeout : cv_status::timeout);
232 class condition_variable_any
234#ifdef _GLIBCXX_USE_PTHREAD_COND_CLOCKWAIT
243 template<
typename _Lock>
246 explicit _Unlock(_Lock& __lk) : _M_lock(__lk) { __lk.unlock(); }
248#pragma GCC diagnostic push
249#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
250 ~_Unlock()
noexcept(
false)
257 { __throw_exception_again; }
264#pragma GCC diagnostic pop
266 _Unlock(
const _Unlock&) =
delete;
267 _Unlock& operator=(
const _Unlock&) =
delete;
274 ~condition_variable_any() =
default;
276 condition_variable_any(
const condition_variable_any&) =
delete;
277 condition_variable_any& operator=(
const condition_variable_any&) =
delete;
280 notify_one()
noexcept
283 _M_cond.notify_one();
287 notify_all()
noexcept
290 _M_cond.notify_all();
293 template<
typename _Lock>
299 _Unlock<_Lock> __unlock(__lock);
303 _M_cond.wait(__my_lock2);
307 template<
typename _Lock,
typename _Predicate>
309 wait(_Lock& __lock, _Predicate __p)
315 template<
typename _Lock,
typename _Clock,
typename _Duration>
317 wait_until(_Lock& __lock,
322 _Unlock<_Lock> __unlock(__lock);
326 return _M_cond.wait_until(__my_lock2, __atime);
329 template<
typename _Lock,
typename _Clock,
330 typename _Duration,
typename _Predicate>
332 wait_until(_Lock& __lock,
337 if (wait_until(__lock, __atime) == cv_status::timeout)
342 template<
typename _Lock,
typename _Rep,
typename _Period>
345 {
return wait_until(__lock, __clock_t::now() + __rtime); }
347 template<
typename _Lock,
typename _Rep,
348 typename _Period,
typename _Predicate>
350 wait_for(_Lock& __lock,
352 {
return wait_until(__lock, __clock_t::now() + __rtime,
std::move(__p)); }
354#ifdef __glibcxx_jthread
355 template <
class _Lock,
class _Predicate>
356 bool wait(_Lock& __lock,
360 if (__stoken.stop_requested())
365 std::stop_callback __cb(__stoken, [
this] { notify_all(); });
370 if (__stoken.stop_requested())
376 _Unlock<_Lock> __unlock(__lock);
378 _M_cond.wait(__my_lock2);
383 template <
class _Lock,
class _Clock,
class _Duration,
class _Predicate>
384 bool wait_until(_Lock& __lock,
389 if (__stoken.stop_requested())
394 std::stop_callback __cb(__stoken, [
this] { notify_all(); });
401 if (__stoken.stop_requested())
405 _Unlock<_Lock> __u(__lock);
407 const auto __status = _M_cond.wait_until(__my_lock2, __abs_time);
408 __stop = (__status == std::cv_status::timeout) || __stoken.stop_requested();
418 template <
class _Lock,
class _Rep,
class _Period,
class _Predicate>
419 bool wait_for(_Lock& __lock,
424 auto __abst = std::chrono::steady_clock::now() + __rel_time;
425 return wait_until(__lock,