From c65b122762bfeba04a7871e4cafda596e35abf7d Mon Sep 17 00:00:00 2001 From: Chee Bin Hoh Date: Sun, 6 Sep 2026 18:41:31 -0400 Subject: [PATCH] improve code --- src/dmn-runtime-state.cpp | 5 +++++ src/dmn-state.cpp | 4 ++-- test/dmn-test-runtime-state.cpp | 2 +- test/dmn-test-state.cpp | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/dmn-runtime-state.cpp b/src/dmn-runtime-state.cpp index bcb28d9..e14b3b1 100644 --- a/src/dmn-runtime-state.cpp +++ b/src/dmn-runtime-state.cpp @@ -149,6 +149,7 @@ void Dmn_Runtime_State::setEndManaged() { void Dmn_Runtime_State::cancel() { bool completeNow{}; + { std::lock_guard lock{m_mutex}; @@ -243,6 +244,7 @@ bool Dmn_Runtime_State::isRunning() const { bool Dmn_Runtime_State::beginStep() { bool callOnStarted{}; + { std::lock_guard lock{m_mutex}; @@ -270,6 +272,7 @@ void Dmn_Runtime_State::complete(Terminal_State terminalState, bool callOnCompleted{}; bool callOnFailed{}; bool callOnCancelled{}; + { std::lock_guard lock{m_mutex}; @@ -319,6 +322,7 @@ void Dmn_Runtime_State::complete(Terminal_State terminalState, void Dmn_Runtime_State::resetQueuedAfterSubmission() { bool completeNow{}; + { std::lock_guard lock{m_mutex}; @@ -482,6 +486,7 @@ void Dmn_Runtime_State_Manager::executeStateStep( void Dmn_Runtime_State_Manager::releaseState(const Dmn_Runtime_State *state) { std::lock_guard lock{m_pendingStatesMutex}; + m_pendingStates.erase(state); } diff --git a/src/dmn-state.cpp b/src/dmn-state.cpp index cd96ab0..ea4d1dc 100644 --- a/src/dmn-state.cpp +++ b/src/dmn-state.cpp @@ -14,10 +14,8 @@ #include #include -#include #include #include -#include namespace dmn { @@ -93,6 +91,7 @@ auto Dmn_State::runNext() -> bool { void Dmn_State::setEnd() { beforeSetEnd(); + m_next = static_cast(m_states.size()); } @@ -109,6 +108,7 @@ void Dmn_State::setNext(int index) { void Dmn_State::setNext() { beforeSetNext(); + assert(m_next >= 0 && m_next < static_cast(m_states.size())); m_next++; } diff --git a/test/dmn-test-runtime-state.cpp b/test/dmn-test-runtime-state.cpp index d173fb3..188d7d9 100644 --- a/test/dmn-test-runtime-state.cpp +++ b/test/dmn-test-runtime-state.cpp @@ -1,5 +1,5 @@ /** - * Copyright © 2024 - 2025 Chee Bin HOH. All rights reserved. + * Copyright © 2026 Chee Bin HOH. All rights reserved. * * @file dmn-test-runtime-state.cpp * @brief Unit tests for runtime-managed state lifecycle and scheduling. diff --git a/test/dmn-test-state.cpp b/test/dmn-test-state.cpp index c2fe91b..bd0d6b7 100644 --- a/test/dmn-test-state.cpp +++ b/test/dmn-test-state.cpp @@ -1,5 +1,5 @@ /** - * Copyright © 2024 - 2025 Chee Bin HOH. All rights reserved. + * Copyright © 2026 Chee Bin HOH. All rights reserved. * * @file dmn-test-state.cpp * @brief Unit tests for Dmn_State lifecycle and user-state transitions.