Skip to content

Commit

Permalink
chore(state-machine): Panic in the case of non-handled non-deferred e…
Browse files Browse the repository at this point in the history
…vents

This just loops through the event-queue at the end of an iteration, and if
there are non-deferred events left in the queue -> panic.

This is a serious logic error if true, and hence will lead to non-defined
behaviour. Thus we simply panic in this case

Signed-off-by: Ole Petter <[email protected]>
  • Loading branch information
oleorhagen committed Nov 1, 2023
1 parent 4f432b2 commit 8966992
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/common/state_machine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,21 @@ class StateMachineRunner : virtual public EventPoster<EventType> {
// actionable until at least one state machine reaches a different state.
PostToEventLoop();
}

// Check if there are any non-deferred events in the queue - then fail if
queue<EventType> queue_copy = event_queue_;
while (not queue_copy.empty()) {
// If we have no more states, but there is still an event left in the
// queue which is not deferred, then we have a serious logic problem. Panic!
EventType event = queue_copy.front();
queue_copy.pop();
for (auto machine : machines_) {
if (machine->deferred_events_.find(event) == machine->deferred_events_.end()) {
log::Fatal(
"The state machine has an unprocessed non-deferred event in the queue. This is a programming error!");
}
}
}
}

void PostToEventLoop() {
Expand Down

0 comments on commit 8966992

Please sign in to comment.