xref: /freebsd/contrib/llvm-project/libcxx/include/condition_variable (revision 700637cbb5e582861067a11aaca4d053546871d2)
10b57cec5SDimitry Andric// -*- C++ -*-
2349cc55cSDimitry Andric//===----------------------------------------------------------------------===//
30b57cec5SDimitry Andric//
40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
70b57cec5SDimitry Andric//
80b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
90b57cec5SDimitry Andric
100b57cec5SDimitry Andric#ifndef _LIBCPP_CONDITION_VARIABLE
110b57cec5SDimitry Andric#define _LIBCPP_CONDITION_VARIABLE
120b57cec5SDimitry Andric
130b57cec5SDimitry Andric/*
140b57cec5SDimitry Andric    condition_variable synopsis
150b57cec5SDimitry Andric
160b57cec5SDimitry Andricnamespace std
170b57cec5SDimitry Andric{
180b57cec5SDimitry Andric
190b57cec5SDimitry Andricenum class cv_status { no_timeout, timeout };
200b57cec5SDimitry Andric
210b57cec5SDimitry Andricclass condition_variable
220b57cec5SDimitry Andric{
230b57cec5SDimitry Andricpublic:
240b57cec5SDimitry Andric    condition_variable();
250b57cec5SDimitry Andric    ~condition_variable();
260b57cec5SDimitry Andric
270b57cec5SDimitry Andric    condition_variable(const condition_variable&) = delete;
280b57cec5SDimitry Andric    condition_variable& operator=(const condition_variable&) = delete;
290b57cec5SDimitry Andric
300b57cec5SDimitry Andric    void notify_one() noexcept;
310b57cec5SDimitry Andric    void notify_all() noexcept;
320b57cec5SDimitry Andric
330b57cec5SDimitry Andric    void wait(unique_lock<mutex>& lock);
340b57cec5SDimitry Andric    template <class Predicate>
350b57cec5SDimitry Andric        void wait(unique_lock<mutex>& lock, Predicate pred);
360b57cec5SDimitry Andric
370b57cec5SDimitry Andric    template <class Clock, class Duration>
380b57cec5SDimitry Andric        cv_status
390b57cec5SDimitry Andric        wait_until(unique_lock<mutex>& lock,
400b57cec5SDimitry Andric                   const chrono::time_point<Clock, Duration>& abs_time);
410b57cec5SDimitry Andric
420b57cec5SDimitry Andric    template <class Clock, class Duration, class Predicate>
430b57cec5SDimitry Andric        bool
440b57cec5SDimitry Andric        wait_until(unique_lock<mutex>& lock,
450b57cec5SDimitry Andric                   const chrono::time_point<Clock, Duration>& abs_time,
460b57cec5SDimitry Andric                   Predicate pred);
470b57cec5SDimitry Andric
480b57cec5SDimitry Andric    template <class Rep, class Period>
490b57cec5SDimitry Andric        cv_status
500b57cec5SDimitry Andric        wait_for(unique_lock<mutex>& lock,
510b57cec5SDimitry Andric                 const chrono::duration<Rep, Period>& rel_time);
520b57cec5SDimitry Andric
530b57cec5SDimitry Andric    template <class Rep, class Period, class Predicate>
540b57cec5SDimitry Andric        bool
550b57cec5SDimitry Andric        wait_for(unique_lock<mutex>& lock,
560b57cec5SDimitry Andric                 const chrono::duration<Rep, Period>& rel_time,
570b57cec5SDimitry Andric                 Predicate pred);
580b57cec5SDimitry Andric
590b57cec5SDimitry Andric    typedef pthread_cond_t* native_handle_type;
600b57cec5SDimitry Andric    native_handle_type native_handle();
610b57cec5SDimitry Andric};
620b57cec5SDimitry Andric
630b57cec5SDimitry Andricvoid notify_all_at_thread_exit(condition_variable& cond, unique_lock<mutex> lk);
640b57cec5SDimitry Andric
650b57cec5SDimitry Andricclass condition_variable_any
660b57cec5SDimitry Andric{
670b57cec5SDimitry Andricpublic:
680b57cec5SDimitry Andric    condition_variable_any();
690b57cec5SDimitry Andric    ~condition_variable_any();
700b57cec5SDimitry Andric
710b57cec5SDimitry Andric    condition_variable_any(const condition_variable_any&) = delete;
720b57cec5SDimitry Andric    condition_variable_any& operator=(const condition_variable_any&) = delete;
730b57cec5SDimitry Andric
740b57cec5SDimitry Andric    void notify_one() noexcept;
750b57cec5SDimitry Andric    void notify_all() noexcept;
760b57cec5SDimitry Andric
770b57cec5SDimitry Andric    template <class Lock>
780b57cec5SDimitry Andric        void wait(Lock& lock);
790b57cec5SDimitry Andric    template <class Lock, class Predicate>
800b57cec5SDimitry Andric        void wait(Lock& lock, Predicate pred);
810b57cec5SDimitry Andric
820b57cec5SDimitry Andric    template <class Lock, class Clock, class Duration>
830b57cec5SDimitry Andric        cv_status
840b57cec5SDimitry Andric        wait_until(Lock& lock,
850b57cec5SDimitry Andric                   const chrono::time_point<Clock, Duration>& abs_time);
860b57cec5SDimitry Andric
870b57cec5SDimitry Andric    template <class Lock, class Clock, class Duration, class Predicate>
880b57cec5SDimitry Andric        bool
890b57cec5SDimitry Andric        wait_until(Lock& lock,
900b57cec5SDimitry Andric                   const chrono::time_point<Clock, Duration>& abs_time,
910b57cec5SDimitry Andric                   Predicate pred);
920b57cec5SDimitry Andric
930b57cec5SDimitry Andric    template <class Lock, class Rep, class Period>
940b57cec5SDimitry Andric        cv_status
950b57cec5SDimitry Andric        wait_for(Lock& lock,
960b57cec5SDimitry Andric                 const chrono::duration<Rep, Period>& rel_time);
970b57cec5SDimitry Andric
980b57cec5SDimitry Andric    template <class Lock, class Rep, class Period, class Predicate>
990b57cec5SDimitry Andric        bool
1000b57cec5SDimitry Andric        wait_for(Lock& lock,
1010b57cec5SDimitry Andric                 const chrono::duration<Rep, Period>& rel_time,
1020b57cec5SDimitry Andric                 Predicate pred);
1035f757f3fSDimitry Andric
1045f757f3fSDimitry Andric    // [thread.condvarany.intwait], interruptible waits
1055f757f3fSDimitry Andric    template <class Lock, class Predicate>
1065f757f3fSDimitry Andric      bool wait(Lock& lock, stop_token stoken, Predicate pred);                               // since C++20
1075f757f3fSDimitry Andric
1085f757f3fSDimitry Andric    template <class Lock, class Clock, class Duration, class Predicate>
1095f757f3fSDimitry Andric      bool wait_until(Lock& lock, stop_token stoken,
1105f757f3fSDimitry Andric                      const chrono::time_point<Clock, Duration>& abs_time, Predicate pred);   // since C++20
1115f757f3fSDimitry Andric
1125f757f3fSDimitry Andric    template <class Lock, class Rep, class Period, class Predicate>
1135f757f3fSDimitry Andric      bool wait_for(Lock& lock, stop_token stoken,
1145f757f3fSDimitry Andric                    const chrono::duration<Rep, Period>& rel_time, Predicate pred);           // since C++20
1150b57cec5SDimitry Andric};
1160b57cec5SDimitry Andric
1170b57cec5SDimitry Andric}  // std
1180b57cec5SDimitry Andric
1190b57cec5SDimitry Andric*/
1200b57cec5SDimitry Andric
121*700637cbSDimitry Andric#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
122*700637cbSDimitry Andric#  include <__cxx03/condition_variable>
123*700637cbSDimitry Andric#else
12406c3fb27SDimitry Andric#  include <__chrono/duration.h>
12506c3fb27SDimitry Andric#  include <__chrono/steady_clock.h>
12606c3fb27SDimitry Andric#  include <__chrono/time_point.h>
12706c3fb27SDimitry Andric#  include <__condition_variable/condition_variable.h>
1280b57cec5SDimitry Andric#  include <__config>
129bdd1243dSDimitry Andric#  include <__memory/shared_ptr.h>
13006c3fb27SDimitry Andric#  include <__mutex/lock_guard.h>
13106c3fb27SDimitry Andric#  include <__mutex/mutex.h>
13206c3fb27SDimitry Andric#  include <__mutex/tag_types.h>
13306c3fb27SDimitry Andric#  include <__mutex/unique_lock.h>
1347a6dacacSDimitry Andric#  include <__stop_token/stop_callback.h>
1355f757f3fSDimitry Andric#  include <__stop_token/stop_token.h>
13606c3fb27SDimitry Andric#  include <__utility/move.h>
13704eeddc0SDimitry Andric#  include <version>
1380b57cec5SDimitry Andric
1390b57cec5SDimitry Andric#  if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1400b57cec5SDimitry Andric#    pragma GCC system_header
1410b57cec5SDimitry Andric#  endif
1420b57cec5SDimitry Andric
143b3edf446SDimitry Andric_LIBCPP_PUSH_MACROS
144b3edf446SDimitry Andric#  include <__undef_macros>
145b3edf446SDimitry Andric
146*700637cbSDimitry Andric#  if _LIBCPP_HAS_THREADS
1470b57cec5SDimitry Andric
1480b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
1490b57cec5SDimitry Andric
1500b57cec5SDimitry Andrictemplate <class _Lock>
1517a6dacacSDimitry Andricstruct __unlock_guard {
1527a6dacacSDimitry Andric  _Lock& __lock_;
1537a6dacacSDimitry Andric
1547a6dacacSDimitry Andric  _LIBCPP_HIDE_FROM_ABI __unlock_guard(_Lock& __lock) : __lock_(__lock) { __lock_.unlock(); }
1557a6dacacSDimitry Andric
1567a6dacacSDimitry Andric  _LIBCPP_HIDE_FROM_ABI ~__unlock_guard() _NOEXCEPT // turns exception to std::terminate
1577a6dacacSDimitry Andric  {
1587a6dacacSDimitry Andric    __lock_.lock();
159cb14a3feSDimitry Andric  }
1607a6dacacSDimitry Andric
1617a6dacacSDimitry Andric  __unlock_guard(const __unlock_guard&)            = delete;
1627a6dacacSDimitry Andric  __unlock_guard& operator=(const __unlock_guard&) = delete;
1630b57cec5SDimitry Andric};
1640b57cec5SDimitry Andric
165*700637cbSDimitry Andricclass _LIBCPP_EXPORTED_FROM_ABI condition_variable_any {
166*700637cbSDimitry Andric  condition_variable __cv_;
167*700637cbSDimitry Andric  shared_ptr<mutex> __mut_;
168*700637cbSDimitry Andric
169*700637cbSDimitry Andricpublic:
170*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI condition_variable_any();
171*700637cbSDimitry Andric
172*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void notify_one() _NOEXCEPT;
173*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void notify_all() _NOEXCEPT;
174*700637cbSDimitry Andric
1750b57cec5SDimitry Andric  template <class _Lock>
176*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void wait(_Lock& __lock) {
1770b57cec5SDimitry Andric    shared_ptr<mutex> __mut = __mut_;
1780b57cec5SDimitry Andric    unique_lock<mutex> __lk(*__mut);
1797a6dacacSDimitry Andric    __unlock_guard<_Lock> __unlock(__lock);
18006c3fb27SDimitry Andric    lock_guard<unique_lock<mutex> > __lx(__lk, adopt_lock_t());
1810b57cec5SDimitry Andric    __cv_.wait(__lk);
1820b57cec5SDimitry Andric  } // __mut_.unlock(), __lock.lock()
1830b57cec5SDimitry Andric
1840b57cec5SDimitry Andric  template <class _Lock, class _Predicate>
185*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void wait(_Lock& __lock, _Predicate __pred);
1860b57cec5SDimitry Andric
1870b57cec5SDimitry Andric  template <class _Lock, class _Clock, class _Duration>
188*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI cv_status wait_until(_Lock& __lock, const chrono::time_point<_Clock, _Duration>& __t) {
1890b57cec5SDimitry Andric    shared_ptr<mutex> __mut = __mut_;
1900b57cec5SDimitry Andric    unique_lock<mutex> __lk(*__mut);
1917a6dacacSDimitry Andric    __unlock_guard<_Lock> __unlock(__lock);
19206c3fb27SDimitry Andric    lock_guard<unique_lock<mutex> > __lx(__lk, adopt_lock_t());
1930b57cec5SDimitry Andric    return __cv_.wait_until(__lk, __t);
1940b57cec5SDimitry Andric  } // __mut_.unlock(), __lock.lock()
1950b57cec5SDimitry Andric
1960b57cec5SDimitry Andric  template <class _Lock, class _Clock, class _Duration, class _Predicate>
197*700637cbSDimitry Andric  bool _LIBCPP_HIDE_FROM_ABI
198*700637cbSDimitry Andric  wait_until(_Lock& __lock, const chrono::time_point<_Clock, _Duration>& __t, _Predicate __pred);
199*700637cbSDimitry Andric
200*700637cbSDimitry Andric  template <class _Lock, class _Rep, class _Period>
201*700637cbSDimitry Andric  cv_status _LIBCPP_HIDE_FROM_ABI wait_for(_Lock& __lock, const chrono::duration<_Rep, _Period>& __d);
202*700637cbSDimitry Andric
203*700637cbSDimitry Andric  template <class _Lock, class _Rep, class _Period, class _Predicate>
204*700637cbSDimitry Andric  bool _LIBCPP_HIDE_FROM_ABI wait_for(_Lock& __lock, const chrono::duration<_Rep, _Period>& __d, _Predicate __pred);
205*700637cbSDimitry Andric
206*700637cbSDimitry Andric#    if _LIBCPP_STD_VER >= 20
207*700637cbSDimitry Andric
208*700637cbSDimitry Andric  template <class _Lock, class _Predicate>
209*700637cbSDimitry Andric  _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI bool wait(_Lock& __lock, stop_token __stoken, _Predicate __pred);
210*700637cbSDimitry Andric
211*700637cbSDimitry Andric  template <class _Lock, class _Clock, class _Duration, class _Predicate>
212*700637cbSDimitry Andric  _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI bool wait_until(
213*700637cbSDimitry Andric      _Lock& __lock, stop_token __stoken, const chrono::time_point<_Clock, _Duration>& __abs_time, _Predicate __pred);
214*700637cbSDimitry Andric
215*700637cbSDimitry Andric  template <class _Lock, class _Rep, class _Period, class _Predicate>
216*700637cbSDimitry Andric  _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI bool
217*700637cbSDimitry Andric  wait_for(_Lock& __lock, stop_token __stoken, const chrono::duration<_Rep, _Period>& __rel_time, _Predicate __pred);
218*700637cbSDimitry Andric
219*700637cbSDimitry Andric#    endif // _LIBCPP_STD_VER >= 20
220*700637cbSDimitry Andric};
221*700637cbSDimitry Andric
222*700637cbSDimitry Andricinline condition_variable_any::condition_variable_any() : __mut_(make_shared<mutex>()) {}
223*700637cbSDimitry Andric
224*700637cbSDimitry Andricinline void condition_variable_any::notify_one() _NOEXCEPT {
225*700637cbSDimitry Andric  { lock_guard<mutex> __lx(*__mut_); }
226*700637cbSDimitry Andric  __cv_.notify_one();
227*700637cbSDimitry Andric}
228*700637cbSDimitry Andric
229*700637cbSDimitry Andricinline void condition_variable_any::notify_all() _NOEXCEPT {
230*700637cbSDimitry Andric  { lock_guard<mutex> __lx(*__mut_); }
231*700637cbSDimitry Andric  __cv_.notify_all();
232*700637cbSDimitry Andric}
233*700637cbSDimitry Andric
234*700637cbSDimitry Andrictemplate <class _Lock, class _Predicate>
235*700637cbSDimitry Andricinline void condition_variable_any::wait(_Lock& __lock, _Predicate __pred) {
236*700637cbSDimitry Andric  while (!__pred())
237*700637cbSDimitry Andric    wait(__lock);
238*700637cbSDimitry Andric}
239*700637cbSDimitry Andric
240*700637cbSDimitry Andrictemplate <class _Lock, class _Clock, class _Duration, class _Predicate>
241cb14a3feSDimitry Andricinline bool
242cb14a3feSDimitry Andriccondition_variable_any::wait_until(_Lock& __lock, const chrono::time_point<_Clock, _Duration>& __t, _Predicate __pred) {
2430b57cec5SDimitry Andric  while (!__pred())
2440b57cec5SDimitry Andric    if (wait_until(__lock, __t) == cv_status::timeout)
2450b57cec5SDimitry Andric      return __pred();
2460b57cec5SDimitry Andric  return true;
2470b57cec5SDimitry Andric}
2480b57cec5SDimitry Andric
2490b57cec5SDimitry Andrictemplate <class _Lock, class _Rep, class _Period>
250cb14a3feSDimitry Andricinline cv_status condition_variable_any::wait_for(_Lock& __lock, const chrono::duration<_Rep, _Period>& __d) {
2510b57cec5SDimitry Andric  return wait_until(__lock, chrono::steady_clock::now() + __d);
2520b57cec5SDimitry Andric}
2530b57cec5SDimitry Andric
2540b57cec5SDimitry Andrictemplate <class _Lock, class _Rep, class _Period, class _Predicate>
255cb14a3feSDimitry Andricinline bool
256cb14a3feSDimitry Andriccondition_variable_any::wait_for(_Lock& __lock, const chrono::duration<_Rep, _Period>& __d, _Predicate __pred) {
257cb14a3feSDimitry Andric  return wait_until(__lock, chrono::steady_clock::now() + __d, std::move(__pred));
2580b57cec5SDimitry Andric}
2590b57cec5SDimitry Andric
260*700637cbSDimitry Andric#    if _LIBCPP_STD_VER >= 20
2615f757f3fSDimitry Andric
2625f757f3fSDimitry Andrictemplate <class _Lock, class _Predicate>
2637a6dacacSDimitry Andricbool condition_variable_any::wait(_Lock& __user_lock, stop_token __stoken, _Predicate __pred) {
2647a6dacacSDimitry Andric  if (__stoken.stop_requested())
2657a6dacacSDimitry Andric    return __pred();
2667a6dacacSDimitry Andric
2677a6dacacSDimitry Andric  // Per https://eel.is/c++draft/thread.condition.condvarany#general-note-2,
2687a6dacacSDimitry Andric  // we do need to take a copy of the shared pointer __mut_
2697a6dacacSDimitry Andric  // This ensures that a thread can call the destructor immediately after calling
2707a6dacacSDimitry Andric  // notify_all, without waiting all the wait calls.
2717a6dacacSDimitry Andric  // A thread can also safely call the destructor immediately after calling
2727a6dacacSDimitry Andric  // request_stop, as the call to request_stop would evaluate the callback,
2737a6dacacSDimitry Andric  // which accesses the internal condition variable, immediately on the same thread.
2747a6dacacSDimitry Andric  // In this situation, it is OK even without copying a shared ownership the internal
2757a6dacacSDimitry Andric  // condition variable. However, this needs the evaluation of stop_callback to
2767a6dacacSDimitry Andric  // happen-before the destruction.
2777a6dacacSDimitry Andric  // The spec only says "Only the notification to unblock the wait needs to happen
2787a6dacacSDimitry Andric  // before destruction". To make this work, we need to copy the shared ownership of
2797a6dacacSDimitry Andric  // the internal condition variable inside this function, which is not possible
2807a6dacacSDimitry Andric  // with the current ABI.
2817a6dacacSDimitry Andric  shared_ptr<mutex> __mut = __mut_;
2827a6dacacSDimitry Andric
2837a6dacacSDimitry Andric  stop_callback __cb(__stoken, [this] { notify_all(); });
2847a6dacacSDimitry Andric
2857a6dacacSDimitry Andric  while (true) {
2865f757f3fSDimitry Andric    if (__pred())
2875f757f3fSDimitry Andric      return true;
2887a6dacacSDimitry Andric
2897a6dacacSDimitry Andric    // We need to take the internal lock before checking stop_requested,
2907a6dacacSDimitry Andric    // so that the notification cannot come in between the stop_requested
2917a6dacacSDimitry Andric    // check and entering the wait.
2927a6dacacSDimitry Andric    // Note that the stop_callback takes the same internal lock before notifying
2937a6dacacSDimitry Andric    unique_lock<mutex> __internal_lock(*__mut);
2947a6dacacSDimitry Andric    if (__stoken.stop_requested())
2957a6dacacSDimitry Andric      break;
2967a6dacacSDimitry Andric
2977a6dacacSDimitry Andric    __unlock_guard<_Lock> __unlock(__user_lock);
2987a6dacacSDimitry Andric    unique_lock<mutex> __internal_lock2(
2997a6dacacSDimitry Andric        std::move(__internal_lock)); // switch unlock order between __internal_lock and __user_lock
3007a6dacacSDimitry Andric    __cv_.wait(__internal_lock2);
3017a6dacacSDimitry Andric  } // __internal_lock2.unlock(), __user_lock.lock()
3025f757f3fSDimitry Andric  return __pred();
3035f757f3fSDimitry Andric}
3045f757f3fSDimitry Andric
3055f757f3fSDimitry Andrictemplate <class _Lock, class _Clock, class _Duration, class _Predicate>
3065f757f3fSDimitry Andricbool condition_variable_any::wait_until(
3077a6dacacSDimitry Andric    _Lock& __user_lock,
3087a6dacacSDimitry Andric    stop_token __stoken,
3097a6dacacSDimitry Andric    const chrono::time_point<_Clock, _Duration>& __abs_time,
3107a6dacacSDimitry Andric    _Predicate __pred) {
3117a6dacacSDimitry Andric  if (__stoken.stop_requested())
3127a6dacacSDimitry Andric    return __pred();
3137a6dacacSDimitry Andric
3147a6dacacSDimitry Andric  shared_ptr<mutex> __mut = __mut_;
3157a6dacacSDimitry Andric  stop_callback __cb(__stoken, [this] { notify_all(); });
3167a6dacacSDimitry Andric
3177a6dacacSDimitry Andric  while (true) {
3185f757f3fSDimitry Andric    if (__pred())
3195f757f3fSDimitry Andric      return true;
3207a6dacacSDimitry Andric
3217a6dacacSDimitry Andric    unique_lock<mutex> __internal_lock(*__mut);
3227a6dacacSDimitry Andric    if (__stoken.stop_requested())
3237a6dacacSDimitry Andric      break;
3247a6dacacSDimitry Andric
3257a6dacacSDimitry Andric    __unlock_guard<_Lock> __unlock(__user_lock);
3267a6dacacSDimitry Andric    unique_lock<mutex> __internal_lock2(
3277a6dacacSDimitry Andric        std::move(__internal_lock)); // switch unlock order between __internal_lock and __user_lock
3287a6dacacSDimitry Andric
3297a6dacacSDimitry Andric    if (__cv_.wait_until(__internal_lock2, __abs_time) == cv_status::timeout)
3307a6dacacSDimitry Andric      break;
3317a6dacacSDimitry Andric  } // __internal_lock2.unlock(), __user_lock.lock()
3325f757f3fSDimitry Andric  return __pred();
3335f757f3fSDimitry Andric}
3345f757f3fSDimitry Andric
3355f757f3fSDimitry Andrictemplate <class _Lock, class _Rep, class _Period, class _Predicate>
3365f757f3fSDimitry Andricbool condition_variable_any::wait_for(
3375f757f3fSDimitry Andric    _Lock& __lock, stop_token __stoken, const chrono::duration<_Rep, _Period>& __rel_time, _Predicate __pred) {
3385f757f3fSDimitry Andric  return wait_until(__lock, std::move(__stoken), chrono::steady_clock::now() + __rel_time, std::move(__pred));
3395f757f3fSDimitry Andric}
3405f757f3fSDimitry Andric
341*700637cbSDimitry Andric#    endif // _LIBCPP_STD_VER >= 20
3425f757f3fSDimitry Andric
34306c3fb27SDimitry Andric_LIBCPP_EXPORTED_FROM_ABI void notify_all_at_thread_exit(condition_variable&, unique_lock<mutex>);
3440b57cec5SDimitry Andric
3450b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD
3460b57cec5SDimitry Andric
347*700637cbSDimitry Andric#  endif // _LIBCPP_HAS_THREADS
3480b57cec5SDimitry Andric
349b3edf446SDimitry Andric_LIBCPP_POP_MACROS
350b3edf446SDimitry Andric
351bdd1243dSDimitry Andric#  if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
35206c3fb27SDimitry Andric#    include <atomic>
353bdd1243dSDimitry Andric#    include <concepts>
35406c3fb27SDimitry Andric#    include <cstdint>
35506c3fb27SDimitry Andric#    include <cstdlib>
35606c3fb27SDimitry Andric#    include <cstring>
35706c3fb27SDimitry Andric#    include <initializer_list>
3585f757f3fSDimitry Andric#    include <iosfwd>
35906c3fb27SDimitry Andric#    include <new>
360*700637cbSDimitry Andric#    include <optional>
36106c3fb27SDimitry Andric#    include <stdexcept>
36206c3fb27SDimitry Andric#    include <system_error>
363bdd1243dSDimitry Andric#    include <type_traits>
36406c3fb27SDimitry Andric#    include <typeinfo>
365bdd1243dSDimitry Andric#  endif
366*700637cbSDimitry Andric#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
367bdd1243dSDimitry Andric
3680b57cec5SDimitry Andric#endif // _LIBCPP_CONDITION_VARIABLE
369