| 1 |
//===----------- TaskDispatchTest.cpp - Test TaskDispatch APIs ------------===// |
| 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-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
#include "llvm/ExecutionEngine/Orc/TaskDispatch.h" |
| 10 |
#include "gtest/gtest.h" |
| 11 |
|
| 12 |
#include <future> |
| 13 |
|
| 14 |
using namespace llvm; |
| 15 |
using namespace llvm::orc; |
| 16 |
|
| 17 |
TEST(InPlaceTaskDispatchTest, GenericNamedTask) { |
| 18 |
auto D = std::make_unique<InPlaceTaskDispatcher>(); |
| 19 |
bool B = false; |
| 20 |
D->dispatch(makeGenericNamedTask([&]() { B = true; })); |
| 21 |
EXPECT_TRUE(B); |
| 22 |
D->shutdown(); |
| 23 |
} |
| 24 |
|
| 25 |
#if LLVM_ENABLE_THREADS |
| 26 |
TEST(DynamicThreadPoolDispatchTest, GenericNamedTask) { |
| 27 |
auto D = std::make_unique<DynamicThreadPoolTaskDispatcher>(); |
| 28 |
std::promise<bool> P; |
| 29 |
auto F = P.get_future(); |
| 30 |
D->dispatch(makeGenericNamedTask( |
| 31 |
[P = std::move(P)]() mutable { P.set_value(true); })); |
| 32 |
EXPECT_TRUE(F.get()); |
| 33 |
D->shutdown(); |
| 34 |
} |
| 35 |
#endif |