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>
166 using __dur =
typename steady_clock::duration;
167 return wait_until(__lock,
168 steady_clock::now() +
172 template<
typename _Rep,
typename _Period,
typename _Predicate>
178 using __dur =
typename steady_clock::duration;
179 return wait_until(__lock,
180 steady_clock::now() +
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);
230 class condition_variable_any
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;
272 ~condition_variable_any() =
default;
274 condition_variable_any(
const condition_variable_any&) =
delete;
275 condition_variable_any& operator=(
const condition_variable_any&) =
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())
363 std::stop_callback __cb(__stoken, [
this] { notify_all(); });
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())
392 std::stop_callback __cb(__stoken, [
this] { notify_all(); });
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,