| 42 | }; |
| 43 | |
| 44 | TEST_F(ConditionVariableTest, testSingleWait) { |
| 45 | auto data = 0; |
| 46 | Notifier notifier; |
| 47 | std::atomic<size_t> latch(2); |
| 48 | |
| 49 | executors::SimpleExecutor e1(1); |
| 50 | executors::SimpleExecutor e2(1); |
| 51 | |
| 52 | auto producer = [&]() -> Lazy<void> { |
| 53 | data = 1; |
| 54 | CHECK_EXECUTOR(&e2); |
| 55 | notifier.notify(); |
| 56 | CHECK_EXECUTOR(&e2); |
| 57 | co_return; |
| 58 | }; |
| 59 | auto awaiter = [&]() -> Lazy<void> { |
| 60 | CHECK_EXECUTOR(&e1); |
| 61 | co_await notifier.wait(); |
| 62 | CHECK_EXECUTOR(&e1); |
| 63 | EXPECT_EQ(1, data); |
| 64 | data = 2; |
| 65 | co_return; |
| 66 | }; |
| 67 | awaiter().via(&e1).start( |
| 68 | [&](Try<void> var) { latch.fetch_sub(1u, std::memory_order_relaxed); }); |
| 69 | producer().via(&e2).start( |
| 70 | [&](Try<void> var) { latch.fetch_sub(1u, std::memory_order_relaxed); }); |
| 71 | while (latch.load(std::memory_order_relaxed)) |
| 72 | ; |
| 73 | EXPECT_EQ(2, data); |
| 74 | } |
| 75 | |
| 76 | TEST_F(ConditionVariableTest, testMultiWait) { |
| 77 | auto data = 0; |
nothing calls this directly
no test coverage detected