1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: no-threads
12 // <condition_variable>
14 // class condition_variable;
16 // template <class Clock, class Duration>
18 // wait_until(unique_lock<mutex>& lock,
19 // const chrono::time_point<Clock, Duration>& abs_time);
21 #include <condition_variable>
27 #include "make_test_thread.h"
28 #include "test_macros.h"
32 typedef std::chrono::milliseconds duration
;
33 typedef duration::rep rep
;
34 typedef duration::period period
;
35 typedef std::chrono::time_point
<TestClock
> time_point
;
36 static const bool is_steady
= true;
38 static time_point
now()
40 using namespace std::chrono
;
41 return time_point(duration_cast
<duration
>(
42 steady_clock::now().time_since_epoch()
47 std::condition_variable cv
;
55 template <typename Clock
>
58 std::unique_lock
<std::mutex
> lk(mut
);
62 typename
Clock::time_point t0
= Clock::now();
63 typename
Clock::time_point t
= t0
+ std::chrono::milliseconds(250);
64 while (test2
== 0 && cv
.wait_until(lk
, t
) == std::cv_status::no_timeout
)
66 typename
Clock::time_point t1
= Clock::now();
69 assert(t1
- t0
< std::chrono::milliseconds(250));
74 assert(t1
- t0
- std::chrono::milliseconds(250) < std::chrono::milliseconds(50));
80 template <typename Clock
>
87 std::unique_lock
<std::mutex
>lk(mut
);
88 std::thread t
= support::make_test_thread(f
<Clock
>);
101 std::unique_lock
<std::mutex
>lk(mut
);
102 std::thread t
= support::make_test_thread(f
<Clock
>);
112 int main(int, char**)
114 run_test
<TestClock
>();
115 run_test
<std::chrono::steady_clock
>();
116 run_test
<std::chrono::system_clock
>();