aboutsummaryrefslogtreecommitdiff
path: root/src/profiling/ProfilingStateMachine.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/profiling/ProfilingStateMachine.cpp')
-rw-r--r--src/profiling/ProfilingStateMachine.cpp93
1 files changed, 93 insertions, 0 deletions
diff --git a/src/profiling/ProfilingStateMachine.cpp b/src/profiling/ProfilingStateMachine.cpp
new file mode 100644
index 0000000000..682e1b8894
--- /dev/null
+++ b/src/profiling/ProfilingStateMachine.cpp
@@ -0,0 +1,93 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include "ProfilingStateMachine.hpp"
+
+#include <armnn/Exceptions.hpp>
+
+namespace armnn
+{
+
+namespace profiling
+{
+
+ProfilingState ProfilingStateMachine::GetCurrentState() const
+{
+ return m_State;
+}
+
+void ProfilingStateMachine::TransitionToState(ProfilingState newState)
+{
+ switch (newState)
+ {
+ case ProfilingState::Uninitialised:
+ {
+ ProfilingState expectedState = m_State.load(std::memory_order::memory_order_relaxed);
+ do {
+ if (!IsOneOfStates(expectedState, ProfilingState::Uninitialised))
+ {
+ throw armnn::Exception(std::string("Cannot transition from state [")
+ + GetProfilingStateName(expectedState)
+ +"] to [" + GetProfilingStateName(newState) + "]");
+ }
+ } while (!m_State.compare_exchange_strong(expectedState, newState,
+ std::memory_order::memory_order_relaxed));
+
+ break;
+ }
+ case ProfilingState::NotConnected:
+ {
+ ProfilingState expectedState = m_State.load(std::memory_order::memory_order_relaxed);
+ do {
+ if (!IsOneOfStates(expectedState, ProfilingState::Uninitialised, ProfilingState::NotConnected,
+ ProfilingState::Active))
+ {
+ throw armnn::Exception(std::string("Cannot transition from state [")
+ + GetProfilingStateName(expectedState)
+ +"] to [" + GetProfilingStateName(newState) + "]");
+ }
+ } while (!m_State.compare_exchange_strong(expectedState, newState,
+ std::memory_order::memory_order_relaxed));
+
+ break;
+ }
+ case ProfilingState::WaitingForAck:
+ {
+ ProfilingState expectedState = m_State.load(std::memory_order::memory_order_relaxed);
+ do {
+ if (!IsOneOfStates(expectedState, ProfilingState::NotConnected, ProfilingState::WaitingForAck))
+ {
+ throw armnn::Exception(std::string("Cannot transition from state [")
+ + GetProfilingStateName(expectedState)
+ +"] to [" + GetProfilingStateName(newState) + "]");
+ }
+ } while (!m_State.compare_exchange_strong(expectedState, newState,
+ std::memory_order::memory_order_relaxed));
+
+ break;
+ }
+ case ProfilingState::Active:
+ {
+ ProfilingState expectedState = m_State.load(std::memory_order::memory_order_relaxed);
+ do {
+ if (!IsOneOfStates(expectedState, ProfilingState::WaitingForAck, ProfilingState::Active))
+ {
+ throw armnn::Exception(std::string("Cannot transition from state [")
+ + GetProfilingStateName(expectedState)
+ +"] to [" + GetProfilingStateName(newState) + "]");
+ }
+ } while (!m_State.compare_exchange_strong(expectedState, newState,
+ std::memory_order::memory_order_relaxed));
+
+ break;
+ }
+ default:
+ break;
+ }
+}
+
+} //namespace profiling
+
+} //namespace armnn \ No newline at end of file