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_any;
16 // template <class Lock, class Duration, class Predicate>
18 // wait_until(Lock& lock,
19 // const chrono::time_point<Clock, Duration>& abs_time,
22 #include <condition_variable>
28 #include "make_test_thread.h"
29 #include "test_macros.h"
33 typedef std::chrono::milliseconds duration
;
34 typedef duration::rep rep
;
35 typedef duration::period period
;
36 typedef std::chrono::time_point
<Clock
> time_point
;
37 static const bool is_steady
= true;
39 static time_point
now()
41 using namespace std::chrono
;
42 return time_point(duration_cast
<duration
>(
43 steady_clock::now().time_since_epoch()
52 explicit Pred(int& i
) : i_(i
) {}
54 bool operator()() {return i_
!= 0;}
57 std::condition_variable_any cv
;
59 typedef std::timed_mutex L0
;
60 typedef std::unique_lock
<L0
> L1
;
75 Clock::time_point t0
= Clock::now();
76 Clock::time_point t
= t0
+ Clock::duration(250);
77 bool r
= cv
.wait_until(lk
, t
, Pred(test2
));
78 Clock::time_point t1
= Clock::now();
81 assert(t1
- t0
< Clock::duration(250));
87 assert(t1
- t0
- Clock::duration(250) < Clock::duration(50));
98 std::thread t
= support::make_test_thread(f
);
112 std::thread t
= support::make_test_thread(f
);