From 3ecc5104a088fe9fd0b504ca0c6c3a932ed342c4 Mon Sep 17 00:00:00 2001 From: Nikhil Raj Date: Tue, 3 Sep 2019 15:55:33 +0100 Subject: IVGCVSW-3431 Create Profiling Service State Machine Change-Id: I30ae52d38181a91ce642e24919ad788902e42eb4 Signed-off-by: Nikhil Raj --- src/profiling/ProfilingStateMachine.cpp | 93 +++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 src/profiling/ProfilingStateMachine.cpp (limited to 'src/profiling/ProfilingStateMachine.cpp') 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 + +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 -- cgit v1.2.1