diff options
author | Nikhil Raj <nikhil.raj@arm.com> | 2019-09-03 15:55:33 +0100 |
---|---|---|
committer | Nikhil Raj <nikhil.raj@arm.com> | 2019-09-03 15:55:33 +0100 |
commit | 3ecc5104a088fe9fd0b504ca0c6c3a932ed342c4 (patch) | |
tree | 7ea04111888647bc53f88003f5d2b44ceed22279 /src/profiling/ProfilingStateMachine.cpp | |
parent | 7388217c07ccbd387d3bcfbde76cca744c4fd6fe (diff) | |
download | armnn-3ecc5104a088fe9fd0b504ca0c6c3a932ed342c4.tar.gz |
IVGCVSW-3431 Create Profiling Service State Machine
Change-Id: I30ae52d38181a91ce642e24919ad788902e42eb4
Signed-off-by: Nikhil Raj <nikhil.raj@arm.com>
Diffstat (limited to 'src/profiling/ProfilingStateMachine.cpp')
-rw-r--r-- | src/profiling/ProfilingStateMachine.cpp | 93 |
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 |