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
18 // template <class Rep, class Period>
20 // wait_for(const chrono::duration<Rep, Period>& rel_time) const;
26 #include "make_test_thread.h"
27 #include "test_macros.h"
29 typedef std::chrono::milliseconds ms
;
31 static const ms
sleepTime(500);
32 static const ms
waitTime(5000);
34 void func1(std::promise
<int> p
)
36 std::this_thread::sleep_for(sleepTime
);
42 void func3(std::promise
<int&> p
)
44 std::this_thread::sleep_for(sleepTime
);
49 void func5(std::promise
<void> p
)
51 std::this_thread::sleep_for(sleepTime
);
55 template <typename T
, typename F
>
56 void test(F func
, bool waitFirst
) {
57 typedef std::chrono::high_resolution_clock Clock
;
59 std::future
<T
> f
= p
.get_future();
60 Clock::time_point t1
, t0
= Clock::now();
61 support::make_test_thread(func
, std::move(p
)).detach();
63 assert(f
.wait_for(ms(1)) == std::future_status::timeout
);
69 assert(f
.wait_for(ms(waitTime
)) == std::future_status::ready
);
72 assert(f
.wait_for(ms(waitTime
)) == std::future_status::ready
);
78 assert(t1
- t0
>= sleepTime
);
83 test
<int>(func1
, true);
84 test
<int&>(func3
, true);
85 test
<void>(func5
, true);
86 test
<int>(func1
, false);
87 test
<int&>(func3
, false);
88 test
<void>(func5
, false);