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_SUPPORT_MAKE_TEST_THREAD_H
10 #define TEST_SUPPORT_MAKE_TEST_THREAD_H
15 #include "test_macros.h"
19 // These functions are used to mock the creation of threads within the test suite.
21 // This provides a vendor-friendly way of making the test suite work even on platforms
22 // where the standard thread constructors don't work (e.g. embedded environments where
23 // creating a thread requires additional information like setting attributes).
25 // Vendors can keep a downstream diff in this file to create threads however they
26 // need on their platform, and the majority of the test suite will work out of the
27 // 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 should
29 // work if they use the utilities in this file.
31 template <class F
, class ...Args
>
32 std::thread
make_test_thread(F
&& f
, Args
&& ...args
) {
33 return std::thread(std::forward
<F
>(f
), std::forward
<Args
>(args
)...);
36 #if TEST_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_STOP_TOKEN)
37 # ifdef _LIBCPP_VERSION
38 # define TEST_AVAILABILITY_SYNC _LIBCPP_AVAILABILITY_SYNC
40 # define TEST_AVAILABILITY_SYNC
43 template <class F
, class... Args
>
44 TEST_AVAILABILITY_SYNC
std::jthread
make_test_jthread(F
&& f
, Args
&&... args
) {
45 return std::jthread(std::forward
<F
>(f
), std::forward
<Args
>(args
)...);
49 } // end namespace support
51 #endif // TEST_SUPPORT_MAKE_TEST_THREAD_H