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>
113#ifdef _GLIBCXX_USE_PTHREAD_COND_CLOCKWAIT
114 template<
typename _Duration>
118 {
return __wait_until_impl(__lock, __atime); }
121 template<
typename _Duration>
125 {
return __wait_until_impl(__lock, __atime); }
127 template<
typename _Clock,
typename _Duration>
132#if __cplusplus > 201703L
133 static_assert(chrono::is_clock_v<_Clock>);
135 using __s_dur =
typename __clock_t::duration;
136 const typename _Clock::time_point __c_entry = _Clock::now();
137 const __clock_t::time_point __s_entry = __clock_t::now();
138 const auto __delta = __atime - __c_entry;
139 const auto __s_atime = __s_entry +
142 if (__wait_until_impl(__lock, __s_atime) == cv_status::no_timeout)
143 return cv_status::no_timeout;
147 if (_Clock::now() < __atime)
148 return cv_status::no_timeout;
149 return cv_status::timeout;
152 template<
typename _Clock,
typename _Duration,
typename _Predicate>
159 if (wait_until(__lock, __atime) == cv_status::timeout)
164 template<
typename _Rep,
typename _Period>
171 using __dur =
typename steady_clock::duration;
172 return wait_until(__lock,
173 steady_clock::now() +
177 template<
typename _Rep,
typename _Period,
typename _Predicate>
183 using __dur =
typename steady_clock::duration;
184 return wait_until(__lock,
185 steady_clock::now() +
192 {
return _M_cond.native_handle(); }
195#ifdef _GLIBCXX_USE_PTHREAD_COND_CLOCKWAIT
196 template<
typename _Dur>
201 __gthread_time_t __ts = chrono::__to_timeout_gthread_time_t(__atime);
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 __gthread_time_t __ts = chrono::__to_timeout_gthread_time_t(__atime);
215 _M_cond.wait_until(*__lock.mutex(), __ts);
217 return (system_clock::now() < __atime
218 ? cv_status::no_timeout : cv_status::timeout);
235 class condition_variable_any
237#ifdef _GLIBCXX_USE_PTHREAD_COND_CLOCKWAIT
246 template<
typename _Lock>
249 explicit _Unlock(_Lock& __lk) : _M_lock(__lk) { __lk.unlock(); }
251#pragma GCC diagnostic push
252#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
253 ~_Unlock()
noexcept(
false)
260 { __throw_exception_again; }
267#pragma GCC diagnostic pop
269 _Unlock(
const _Unlock&) =
delete;
270 _Unlock& operator=(
const _Unlock&) =
delete;
277 ~condition_variable_any() =
default;
279 condition_variable_any(
const condition_variable_any&) =
delete;
280 condition_variable_any& operator=(
const condition_variable_any&) =
delete;
283 notify_one()
noexcept
286 _M_cond.notify_one();
290 notify_all()
noexcept
293 _M_cond.notify_all();
296 template<
typename _Lock>
302 _Unlock<_Lock> __unlock(__lock);
306 _M_cond.wait(__my_lock2);
310 template<
typename _Lock,
typename _Predicate>
312 wait(_Lock& __lock, _Predicate __p)
321 template<
typename _Lock,
typename _Clock,
typename _Duration>
323 wait_until(_Lock& __lock,
328 _Unlock<_Lock> __unlock(__lock);
332 return _M_cond.wait_until(__my_lock2, __atime);
335 template<
typename _Lock,
typename _Clock,
336 typename _Duration,
typename _Predicate>
338 wait_until(_Lock& __lock,
343 if (wait_until(__lock, __atime) == cv_status::timeout)
348 template<
typename _Lock,
typename _Rep,
typename _Period>
351 {
return wait_until(__lock, __clock_t::now() + __rtime); }
353 template<
typename _Lock,
typename _Rep,
354 typename _Period,
typename _Predicate>
356 wait_for(_Lock& __lock,
358 {
return wait_until(__lock, __clock_t::now() + __rtime,
std::move(__p)); }
360#ifdef __glibcxx_jthread
361 template <
class _Lock,
class _Predicate>
362 bool wait(_Lock& __lock,
366 if (__stoken.stop_requested())
371 std::stop_callback __cb(__stoken, [
this] { notify_all(); });
376 if (__stoken.stop_requested())
382 _Unlock<_Lock> __unlock(__lock);
384 _M_cond.wait(__my_lock2);
389 template <
class _Lock,
class _Clock,
class _Duration,
class _Predicate>
390 bool wait_until(_Lock& __lock,
395 if (__stoken.stop_requested())
400 std::stop_callback __cb(__stoken, [
this] { notify_all(); });
407 if (__stoken.stop_requested())
411 _Unlock<_Lock> __u(__lock);
413 const auto __status = _M_cond.wait_until(__my_lock2, __abs_time);
414 __stop = (__status == std::cv_status::timeout) || __stoken.stop_requested();
424 template <
class _Lock,
class _Rep,
class _Period,
class _Predicate>
425 bool wait_for(_Lock& __lock,
430 auto __abst = std::chrono::steady_clock::now() + __rel_time;
431 return wait_until(__lock,