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_SUPPORT_MAKE_TEST_THREAD_H10#define TEST_SUPPORT_MAKE_TEST_THREAD_H11 12#include <thread>13#include <utility>14 15#include "test_macros.h"16 17namespace support {18 19// These functions are used to mock the creation of threads within the test suite.20//21// This provides a vendor-friendly way of making the test suite work even on platforms22// where the standard thread constructors don't work (e.g. embedded environments where23// creating a thread requires additional information like setting attributes).24//25// Vendors can keep a downstream diff in this file to create threads however they26// need on their platform, and the majority of the test suite will work out of the27// box. Of course, tests that exercise the standard thread constructors won't work,28// but any other test that only creates threads as a side effect of testing should29// work if they use the utilities in this file.30 31template <class F, class... Args>32std::thread make_test_thread(F&& f, Args&&... args) {33 return std::thread(std::forward<F>(f), std::forward<Args>(args)...);34}35 36#if TEST_STD_VER >= 2037template <class F, class... Args>38std::jthread make_test_jthread(F&& f, Args&&... args) {39 return std::jthread(std::forward<F>(f), std::forward<Args>(args)...);40}41#endif42 43} // namespace support44 45#endif // TEST_SUPPORT_MAKE_TEST_THREAD_H46