From 096413acd19fd19b396057f64e963e21dd7b40f5 Mon Sep 17 00:00:00 2001 From: Christian Granzin Date: Mon, 15 Jun 2026 21:28:29 +0200 Subject: [PATCH 1/2] feat(backmp11): event pool configuration --- .../ROOT/attachments/backmp11/BackAdapter.cpp | 1 + .../backmp11/HeaplessStateMachine.cpp | 29 +++++++++------- doc/modules/ROOT/pages/backmp11-back-end.adoc | 34 ++++++++++++++----- .../pages/backmp11-back-end/examples.adoc | 2 +- doc/modules/ROOT/pages/version-history.adoc | 3 +- .../backmp11/detail/event_pool_processor.hpp | 26 ++++++++------ .../backmp11/detail/state_machine_base.hpp | 6 ++-- .../msm/backmp11/state_machine_config.hpp | 33 +++++++++++++----- test/Backmp11Transitions.cpp | 3 +- 9 files changed, 89 insertions(+), 48 deletions(-) diff --git a/doc/modules/ROOT/attachments/backmp11/BackAdapter.cpp b/doc/modules/ROOT/attachments/backmp11/BackAdapter.cpp index 4dfbc55e..e9dcc5ec 100644 --- a/doc/modules/ROOT/attachments/backmp11/BackAdapter.cpp +++ b/doc/modules/ROOT/attachments/backmp11/BackAdapter.cpp @@ -81,6 +81,7 @@ struct back_config_adapter : boost::msm::backmp11::state_machine_config template using event_pool_container = typename QueueContainerPolicy::template In::type; + using event_pool = boost::msm::backmp11::event_pool; }; template diff --git a/doc/modules/ROOT/attachments/backmp11/HeaplessStateMachine.cpp b/doc/modules/ROOT/attachments/backmp11/HeaplessStateMachine.cpp index cd1d6b6b..a0c7df6c 100644 --- a/doc/modules/ROOT/attachments/backmp11/HeaplessStateMachine.cpp +++ b/doc/modules/ROOT/attachments/backmp11/HeaplessStateMachine.cpp @@ -26,13 +26,26 @@ namespace mp11 = boost::mp11; namespace { +static constexpr size_t max_event_size = 32; + +struct MyConfig : back::state_machine_config +{ + // Use a static vector as event pool container. + // This container is sufficient for enqueueing and deferring events, + // but it does not support completion transitions. + // If needed, use a heapless deque implementation (e.g. etl::deque). + template + using static_vector = boost::container::static_vector; + using event_pool = + back::event_pool; +}; + // Events. struct Greet { // A heapless event must be copy constructible and nothrow move constructible. - // The maximum size depends on alignment requirements and the target system, - // 32 bytes should always work. - alignas(void*) std::array message{}; + std::array message{}; }; // Actions. @@ -65,16 +78,6 @@ struct MyStateMachine_ : front::state_machine_def >; }; -struct MyConfig : back::state_machine_config -{ - // Use a static vector as event pool container. - // This container is sufficient for enqueueing and deferring events, - // but it does not support completion transitions. - // If needed, use a heapless deque implementation (e.g. etl::deque). - template - using event_pool_container = boost::container::static_vector; -}; - using MyStateMachine = back::state_machine; [[maybe_unused]] void heapless_state_machine_example() diff --git a/doc/modules/ROOT/pages/backmp11-back-end.adoc b/doc/modules/ROOT/pages/backmp11-back-end.adoc index 574c9559..41259976 100644 --- a/doc/modules/ROOT/pages/backmp11-back-end.adoc +++ b/doc/modules/ROOT/pages/backmp11-back-end.adoc @@ -63,9 +63,8 @@ struct default_state_machine_config using context = no_context; // Optimizes for runtime speed or compile time. using compile_policy = favor_runtime_speed; - // Configures the container type of the event pool. - template - using event_pool_container = std::deque; + // Configures the event pool. + using event_pool = backmp11::event_pool; // Type of the Fsm parameter passed in actions and guards. using fsm_parameter = local_transition_owner; // Sets up an observer for monitoring state machine activities. @@ -174,12 +173,22 @@ When a transition defined in SM1 causes SM2 and SM3 to exit: === Event pool -The setting `event_pool_container` defines the container type of the state machine's event pool. It requires an event pool to handle event enqueueing, deferral, and completion transitions. The default event pool container is a `std::deque`. +The setting `event_pool` configures the container and inline storage the back-end uses to hold work that cannot be processed immediately: enqueued events, deferred events, and completion transitions. -The event pool container can be customized with `using event_pool_container = MyEventPoolContainer;`. It has to support push without iterator invalidation, specifically the following API calls: +```cpp +template