brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.5 KiB · 83687a1 Raw
46 lines · c
1//===----------------------------------------------------------------------===//2//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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef TEST_STD_THREAD_CONDITION_CONDVARANY_HELPERS_H10#define TEST_STD_THREAD_CONDITION_CONDVARANY_HELPERS_H11 12#include <chrono>13#include <cassert>14 15#include "test_macros.h"16 17#if TEST_STD_VER >= 1718 19// wait_for and wait_until function can exit via20// - predicate is true21// - timeout22// - stop_requested23// The return value only tells if the predicate is true24// when the function exits, but it does not tell whether25// it is timeout or stop_requested.26//27// ElapsedTimeCheck would fail the test if a test takes28// longer than a duration. This is useful because we can29// ensure that the wait_{for, until} function does not30// wait until the timeout31struct ElapsedTimeCheck {32  ElapsedTimeCheck(std::chrono::steady_clock::duration timeoutDuration)33      : timeout_(std::chrono::steady_clock::now() + timeoutDuration) {}34 35  ElapsedTimeCheck(ElapsedTimeCheck&&)            = delete;36  ElapsedTimeCheck& operator=(ElapsedTimeCheck&&) = delete;37 38  ~ElapsedTimeCheck() { assert(std::chrono::steady_clock::now() < timeout_); }39 40  std::chrono::time_point<std::chrono::steady_clock> timeout_;41};42 43#endif44 45#endif // TEST_STD_THREAD_CONDITION_CONDVARANY_HELPERS_H46