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/attachments/backmp11/serializer/BoostJson.cpp b/doc/modules/ROOT/attachments/backmp11/serializer/BoostJson.cpp index 1e9b7e59..c5207fd9 100644 --- a/doc/modules/ROOT/attachments/backmp11/serializer/BoostJson.cpp +++ b/doc/modules/ROOT/attachments/backmp11/serializer/BoostJson.cpp @@ -55,6 +55,7 @@ std::string to_boost_json_string(const DimSwitch& dim_switch) // Turn On (state id 1) and set brightness to 75. dim_switch.process_event(TurnOn{}); + dim_switch.process_event(Dim{75}); // Prints: // {"front_end":{"brightness":75},"states":{"1":{"times_pressed":1}},"active_state_ids":[1],"stopped":false} std::cout << to_boost_json_string(dim_switch) << std::endl; diff --git a/doc/modules/ROOT/attachments/backmp11/serializer/NlohmannJson.cpp b/doc/modules/ROOT/attachments/backmp11/serializer/NlohmannJson.cpp index a27e2125..e0ef722b 100644 --- a/doc/modules/ROOT/attachments/backmp11/serializer/NlohmannJson.cpp +++ b/doc/modules/ROOT/attachments/backmp11/serializer/NlohmannJson.cpp @@ -70,6 +70,7 @@ std::string to_nlohmann_json_string(const DimSwitch& dim_switch) // Turn On (state id 1) and set brightness to 75. dim_switch.process_event(TurnOn{}); + dim_switch.process_event(Dim{75}); // Prints: // { // "active_state_ids": [ 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