|
12 | 12 | #include "llvm/Testing/Support/Error.h" |
13 | 13 | #include "gtest/gtest.h" |
14 | 14 |
|
| 15 | +#include <variant> |
| 16 | + |
15 | 17 | using namespace llvm; |
16 | 18 | using namespace llvm::orc; |
17 | 19 | using namespace llvm::orc::shared; |
18 | 20 |
|
19 | 21 | namespace { |
20 | 22 |
|
21 | 23 | Expected<ExecutorAddrRange> reserve(MemoryMapper &M, size_t NumBytes) { |
22 | | - std::promise<MSVCPExpected<ExecutorAddrRange>> P; |
23 | | - auto F = P.get_future(); |
24 | | - M.reserve(NumBytes, [&](auto R) { P.set_value(std::move(R)); }); |
25 | | - return F.get(); |
| 24 | + std::variant<std::monostate, Expected<ExecutorAddrRange>> Result; |
| 25 | + M.reserve(NumBytes, [&](auto R) { Result = std::move(R); }); |
| 26 | + assert(!std::holds_alternative<std::monostate>(Result) && |
| 27 | + "MemoryMapper operations should complete synchronously in tests"); |
| 28 | + return std::move(std::get<Expected<ExecutorAddrRange>>(Result)); |
26 | 29 | } |
27 | 30 |
|
28 | 31 | Expected<ExecutorAddr> initialize(MemoryMapper &M, |
29 | 32 | MemoryMapper::AllocInfo &AI) { |
30 | | - std::promise<MSVCPExpected<ExecutorAddr>> P; |
31 | | - auto F = P.get_future(); |
32 | | - M.initialize(AI, [&](auto R) { P.set_value(std::move(R)); }); |
33 | | - return F.get(); |
| 33 | + std::variant<std::monostate, Expected<ExecutorAddr>> Result; |
| 34 | + M.initialize(AI, [&](auto R) { Result = std::move(R); }); |
| 35 | + assert(!std::holds_alternative<std::monostate>(Result) && |
| 36 | + "MemoryMapper operations should complete synchronously in tests"); |
| 37 | + return std::move(std::get<Expected<ExecutorAddr>>(Result)); |
34 | 38 | } |
35 | 39 |
|
36 | 40 | Error deinitialize(MemoryMapper &M, |
37 | 41 | const std::vector<ExecutorAddr> &Allocations) { |
38 | | - std::promise<MSVCPError> P; |
39 | | - auto F = P.get_future(); |
40 | | - M.deinitialize(Allocations, [&](auto R) { P.set_value(std::move(R)); }); |
41 | | - return F.get(); |
| 42 | + std::variant<std::monostate, Error> Result; |
| 43 | + M.deinitialize(Allocations, [&](auto R) { Result = std::move(R); }); |
| 44 | + assert(!std::holds_alternative<std::monostate>(Result) && |
| 45 | + "MemoryMapper operations should complete synchronously in tests"); |
| 46 | + return std::move(std::get<Error>(Result)); |
42 | 47 | } |
43 | 48 |
|
44 | 49 | Error release(MemoryMapper &M, const std::vector<ExecutorAddr> &Reservations) { |
45 | | - std::promise<MSVCPError> P; |
46 | | - auto F = P.get_future(); |
47 | | - M.release(Reservations, [&](auto R) { P.set_value(std::move(R)); }); |
48 | | - return F.get(); |
| 50 | + std::variant<std::monostate, Error> Result; |
| 51 | + M.release(Reservations, [&](auto R) { Result = std::move(R); }); |
| 52 | + assert(!std::holds_alternative<std::monostate>(Result) && |
| 53 | + "MemoryMapper operations should complete synchronously in tests"); |
| 54 | + return std::move(std::get<Error>(Result)); |
49 | 55 | } |
50 | 56 |
|
51 | 57 | // A basic function to be used as both initializer/deinitializer |
|
0 commit comments