FSM (5): multi-waiter mailbox (engine foundation)
ExecutionContext had a single Waiter slot, so only one coroutine could park on events at a time. Replace it with a FIFO list of waiters: set_waiter appends (each with a unique id + its own timer); deliver routes an event to the first parked waiter that wants its type, else buffers; a timeout fires only its own waiter (found by id). Single-consumer invariant unchanged — all mailbox mutation stays on the consumer thread. Pure refactor (no API change); unblocks parallel regions and deferred events. 995 tests (992 green, 3 skipped), ASan clean, -Werror clean. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ec9e466d7a
commit
c6b7306614
2 files changed
+37
-26
No files matched your search
@@ -137,17 +137,15 @@ namespace Void::Fsm::Detail
|
||||
Async::MpscQueue<EventEnvelope> m_queue;
|
||||
|
||||
std::unordered_map<std::type_index, std::deque<std::any>> m_buffers;
|
||||
using WaiterId = std::uint64_t;
|
||||
struct Waiter {
|
||||
WaiterId id{0};
|
||||
std::vector<const std::type_info*> types;
|
||||
std::coroutine_handle<> cont{};
|
||||
EventEnvelope* slot{nullptr};
|
||||
bool* timed_out{nullptr};
|
||||
TimerId timer{0};
|
||||
|
||||
[[nodiscard]] bool active() const noexcept
|
||||
{
|
||||
return static_cast<bool>(cont);
|
||||
}
|
||||
[[nodiscard]] bool wants(const std::type_info& t) const
|
||||
{
|
||||
for (const auto* ty : types) {
|
||||
@@ -158,7 +156,10 @@ namespace Void::Fsm::Detail
|
||||
return false;
|
||||
}
|
||||
};
|
||||
Waiter m_waiter;
|
||||
// Several waiters can be parked at once (parallel regions, deferred
|
||||
// events). An event resumes the first (FIFO) that wants its type.
|
||||
std::vector<Waiter> m_waiters;
|
||||
WaiterId m_next_waiter{1};
|
||||
|
||||
struct Timer {
|
||||
std::chrono::steady_clock::time_point deadline;
|
||||
|
||||
Reference in new issue
Block a user