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 #ifndef TEST_STD_THREAD_CONDITION_CONDVARANY_HELPERS_H
10 #define TEST_STD_THREAD_CONDITION_CONDVARANY_HELPERS_H
15 #include "test_macros.h"
17 #if TEST_STD_VER >= 17
19 // wait_for and wait_until function can exit via
20 // - predicate is true
23 // The return value only tells if the predicate is true
24 // when the function exits, but it does not tell whether
25 // it is timeout or stop_requested.
27 // ElapsedTimeCheck would fail the test if a test takes
28 // longer than a duration. This is useful because we can
29 // ensure that the wait_{for, until} function does not
30 // wait until the timeout
31 struct ElapsedTimeCheck
{
32 ElapsedTimeCheck(std::chrono::steady_clock::duration timeoutDuration
)
33 : timeout_(std::chrono::steady_clock::now() + timeoutDuration
) {}
35 ElapsedTimeCheck(ElapsedTimeCheck
&&) = delete;
36 ElapsedTimeCheck
& operator=(ElapsedTimeCheck
&&) = delete;
38 ~ElapsedTimeCheck() { assert(std::chrono::steady_clock::now() < timeout_
); }
40 std::chrono::time_point
<std::chrono::steady_clock
> timeout_
;
45 #endif // TEST_STD_THREAD_CONDITION_CONDVARANY_HELPERS_H