diff --git a/smacc/include/smacc/impl/smacc_state_machine_impl.h b/smacc/include/smacc/impl/smacc_state_machine_impl.h index d014127e5..01084c384 100644 --- a/smacc/include/smacc/impl/smacc_state_machine_impl.h +++ b/smacc/include/smacc/impl/smacc_state_machine_impl.h @@ -426,10 +426,7 @@ namespace smacc this->updateStatusMessage(); - { - std::lock_guard lock(m_mutex_); - stateMachineCurrentAction = StateMachineInternalAction::STATE_STEADY; - } + stateMachineCurrentAction = StateMachineInternalAction::STATE_STEADY; } template @@ -444,26 +441,19 @@ namespace smacc this->updateStatusMessage(); - { - std::lock_guard lock(m_mutex_); - stateMachineCurrentAction = StateMachineInternalAction::STATE_ENTERING; - } + stateMachineCurrentAction = StateMachineInternalAction::STATE_ENTERING; } template void ISmaccStateMachine::notifyOnRuntimeConfigured(StateType *state) { - std::lock_guard lock(m_mutex_); stateMachineCurrentAction = StateMachineInternalAction::STATE_CONFIGURING; } template void ISmaccStateMachine::notifyOnStateExitting(StateType *state) { - { - std::lock_guard lock(m_mutex_); - stateMachineCurrentAction = StateMachineInternalAction::STATE_EXITING; - } + stateMachineCurrentAction = StateMachineInternalAction::STATE_EXITING; auto fullname = demangleSymbol(typeid(StateType).name()); ROS_WARN_STREAM("exiting state: " << fullname); @@ -533,7 +523,6 @@ namespace smacc ROS_WARN_STREAM("state exit: " << fullname); { - std::lock_guard lock(m_mutex_); currentState_ = nullptr; stateMachineCurrentAction = StateMachineInternalAction::TRANSITIONING; } diff --git a/smacc/include/smacc/smacc_state_base.h b/smacc/include/smacc/smacc_state_base.h index 827b4d43a..f425c3343 100644 --- a/smacc/include/smacc/smacc_state_base.h +++ b/smacc/include/smacc/smacc_state_base.h @@ -10,6 +10,8 @@ #include #include +#include + namespace smacc { using namespace smacc::introspection; @@ -458,7 +460,9 @@ namespace smacc static_cast(this)->onEntry(); // here orthogonals and client behaviors are entered OnEntry - this->getStateMachine().notifyOnStateEntryEnd(derivedthis); + if (std::is_same, InnerInitial>::value) { + this->getStateMachine().notifyOnStateEntryEnd(derivedthis); + } } }; } // namespace smacc diff --git a/smacc/include/smacc/smacc_state_machine.h b/smacc/include/smacc/smacc_state_machine.h index fe04c1535..9329dd197 100644 --- a/smacc/include/smacc/smacc_state_machine.h +++ b/smacc/include/smacc/smacc_state_machine.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -182,7 +183,7 @@ class ISmaccStateMachine std::recursive_mutex m_mutex_; std::recursive_mutex eventQueueMutex_; - StateMachineInternalAction stateMachineCurrentAction; + std::atomic stateMachineCurrentAction; std::list stateCallbackConnections; diff --git a/smacc/src/smacc/signal_detector.cpp b/smacc/src/smacc/signal_detector.cpp index d2729bb40..16d61d1e5 100644 --- a/smacc/src/smacc/signal_detector.cpp +++ b/smacc/src/smacc/signal_detector.cpp @@ -196,13 +196,10 @@ void SignalDetector::pollOnce() } } - auto currentStateMachineAction = this->smaccStateMachine_->stateMachineCurrentAction; + auto currentStateMachineAction = this->smaccStateMachine_->stateMachineCurrentAction.load(); // STATE UPDATABLE ELEMENTS - if (currentStateMachineAction != StateMachineInternalAction::TRANSITIONING && - currentStateMachineAction != StateMachineInternalAction::STATE_CONFIGURING && - currentStateMachineAction != StateMachineInternalAction::STATE_EXITING && - currentStateMachineAction != StateMachineInternalAction::STATE_ENTERING) + if (currentStateMachineAction == StateMachineInternalAction::STATE_STEADY) { // we do not update updatable elements during trasitioning or configuration of states long currentStateIndex = smaccStateMachine_->getCurrentStateCounter();