74#ifdef _GLIBCXX_USE_PTHREAD_COND_CLOCKWAIT
83 typedef __gthread_cond_t* native_handle_type;
92 notify_one()
noexcept;
95 notify_all()
noexcept;
100 template<
typename _Predicate>
108#ifdef _GLIBCXX_USE_PTHREAD_COND_CLOCKWAIT
109 template<
typename _Duration>
113 {
return __wait_until_impl(__lock, __atime); }
116 template<
typename _Duration>
120 {
return __wait_until_impl(__lock, __atime); }
122 template<
typename _Clock,
typename _Duration>
127#if __cplusplus > 201703L
128 static_assert(chrono::is_clock_v<_Clock>);
130 using __s_dur =
typename __clock_t::duration;
131 const typename _Clock::time_point __c_entry = _Clock::now();
133 const auto __delta = __atime - __c_entry;
134 const auto __s_atime = __s_entry +
135 chrono::__detail::ceil<__s_dur>(__delta);
137 if (__wait_until_impl(__lock, __s_atime) == cv_status::no_timeout)
138 return cv_status::no_timeout;
142 if (_Clock::now() < __atime)
143 return cv_status::no_timeout;
144 return cv_status::timeout;
147 template<
typename _Clock,
typename _Duration,
typename _Predicate>
154 if (wait_until(__lock, __atime) == cv_status::timeout)
159 template<
typename _Rep,
typename _Period>
164 using __dur =
typename steady_clock::duration;
165 return wait_until(__lock,
166 steady_clock::now() +
167 chrono::__detail::ceil<__dur>(__rtime));
170 template<
typename _Rep,
typename _Period,
typename _Predicate>
176 using __dur =
typename steady_clock::duration;
177 return wait_until(__lock,
178 steady_clock::now() +
179 chrono::__detail::ceil<__dur>(__rtime),
185 {
return _M_cond.native_handle(); }
188#ifdef _GLIBCXX_USE_PTHREAD_COND_CLOCKWAIT
189 template<
typename _Dur>
194 auto __s = chrono::time_point_cast<chrono::seconds>(__atime);
195 auto __ns = chrono::duration_cast<chrono::nanoseconds>(__atime - __s);
197 __gthread_time_t __ts =
199 static_cast<std::time_t
>(__s.time_since_epoch().count()),
200 static_cast<long>(__ns.count())
203 _M_cond.wait_until(*__lock.mutex(), CLOCK_MONOTONIC, __ts);
205 return (steady_clock::now() < __atime
206 ? cv_status::no_timeout : cv_status::timeout);
210 template<
typename _Dur>
215 auto __s = chrono::time_point_cast<chrono::seconds>(__atime);
216 auto __ns = chrono::duration_cast<chrono::nanoseconds>(__atime - __s);
218 __gthread_time_t __ts =
220 static_cast<std::time_t
>(__s.time_since_epoch().count()),
221 static_cast<long>(__ns.count())
224 _M_cond.wait_until(*__lock.mutex(), __ts);
226 return (system_clock::now() < __atime
227 ? cv_status::no_timeout : cv_status::timeout);
246#ifdef _GLIBCXX_USE_PTHREAD_COND_CLOCKWAIT
255 template<
typename _Lock>
258 explicit _Unlock(_Lock& __lk) : _M_lock(__lk) { __lk.unlock(); }
260#pragma GCC diagnostic push
261#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
262 ~_Unlock()
noexcept(
false)
269 { __throw_exception_again; }
276#pragma GCC diagnostic pop
278 _Unlock(
const _Unlock&) =
delete;
279 _Unlock& operator=(
const _Unlock&) =
delete;
292 notify_one()
noexcept
295 _M_cond.notify_one();
299 notify_all()
noexcept
302 _M_cond.notify_all();
305 template<
typename _Lock>
311 _Unlock<_Lock> __unlock(__lock);
315 _M_cond.wait(__my_lock2);
319 template<
typename _Lock,
typename _Predicate>
321 wait(_Lock& __lock, _Predicate __p)
327 template<
typename _Lock,
typename _Clock,
typename _Duration>
329 wait_until(_Lock& __lock,
334 _Unlock<_Lock> __unlock(__lock);
338 return _M_cond.wait_until(__my_lock2, __atime);
341 template<
typename _Lock,
typename _Clock,
342 typename _Duration,
typename _Predicate>
344 wait_until(_Lock& __lock,
349 if (wait_until(__lock, __atime) == cv_status::timeout)
354 template<
typename _Lock,
typename _Rep,
typename _Period>
357 {
return wait_until(__lock, __clock_t::now() + __rtime); }
359 template<
typename _Lock,
typename _Rep,
360 typename _Period,
typename _Predicate>
362 wait_for(_Lock& __lock,
364 {
return wait_until(__lock, __clock_t::now() + __rtime,
std::move(__p)); }
366#ifdef __glibcxx_jthread
367 template <
class _Lock,
class _Predicate>
368 bool wait(_Lock& __lock,
372 if (__stoken.stop_requested())
382 if (__stoken.stop_requested())
388 _Unlock<_Lock> __unlock(__lock);
390 _M_cond.wait(__my_lock2);
395 template <
class _Lock,
class _Clock,
class _Duration,
class _Predicate>
396 bool wait_until(_Lock& __lock,
401 if (__stoken.stop_requested())
413 if (__stoken.stop_requested())
417 _Unlock<_Lock> __u(__lock);
419 const auto __status = _M_cond.wait_until(__my_lock2, __abs_time);
420 __stop = (__status == std::cv_status::timeout) || __stoken.stop_requested();
430 template <
class _Lock,
class _Rep,
class _Period,
class _Predicate>
431 bool wait_for(_Lock& __lock,
436 auto __abst = std::chrono::steady_clock::now() + __rel_time;
437 return wait_until(__lock,