diff options
author | FinnWilliamsArm <Finn.Williams@arm.com> | 2019-09-17 16:53:53 +0100 |
---|---|---|
committer | Jim Flynn Arm <jim.flynn@arm.com> | 2019-09-24 23:44:51 +0000 |
commit | 4833cea9036df428634cf64d8f1c4b54fc5da41f (patch) | |
tree | ab5857df8a0761b4df2d894ed0785a9b6db64363 /src/profiling/CommandThread.cpp | |
parent | 11b2eca4ab0c0e897b858f61be7e6b90f810fd2b (diff) | |
download | armnn-4833cea9036df428634cf64d8f1c4b54fc5da41f.tar.gz |
IVGCVSW-3439 Create the Command Thread
Signed-off-by: FinnWilliamsArm <Finn.Williams@arm.com>
Change-Id: I9548c5937967f4c25841bb851273168379687bcd
Diffstat (limited to 'src/profiling/CommandThread.cpp')
-rw-r--r-- | src/profiling/CommandThread.cpp | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/src/profiling/CommandThread.cpp b/src/profiling/CommandThread.cpp new file mode 100644 index 0000000000..4cd622c477 --- /dev/null +++ b/src/profiling/CommandThread.cpp @@ -0,0 +1,97 @@ +// +// Copyright © 2019 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include <atomic> +#include "CommandThread.hpp" + +namespace armnn +{ + +namespace profiling +{ + +CommandThread::CommandThread(uint32_t timeout, + bool stopAfterTimeout, + CommandHandlerRegistry& commandHandlerRegistry, + PacketVersionResolver& packetVersionResolver, + IProfilingConnection& socketProfilingConnection) + : m_Timeout(timeout) + , m_StopAfterTimeout(stopAfterTimeout) + , m_IsRunning(false) + , m_CommandHandlerRegistry(commandHandlerRegistry) + , m_PacketVersionResolver(packetVersionResolver) + , m_SocketProfilingConnection(socketProfilingConnection) +{}; + +void CommandThread::WaitForPacket() +{ + do { + try + { + Packet packet = m_SocketProfilingConnection.ReadPacket(m_Timeout); + Version version = m_PacketVersionResolver.ResolvePacketVersion(packet.GetPacketId()); + + CommandHandlerFunctor* commandHandlerFunctor = + m_CommandHandlerRegistry.GetFunctor(packet.GetPacketId(), version.GetEncodedValue()); + commandHandlerFunctor->operator()(packet); + } + catch(armnn::TimeoutException) + { + if(m_StopAfterTimeout) + { + m_IsRunning.store(false, std::memory_order_relaxed); + return; + } + } + catch(...) + { + //might want to differentiate the errors more + m_IsRunning.store(false, std::memory_order_relaxed); + return; + } + + } while(m_KeepRunning.load(std::memory_order_relaxed)); + + m_IsRunning.store(false, std::memory_order_relaxed); +} + +void CommandThread::Start() +{ + if (!m_CommandThread.joinable() && !IsRunning()) + { + m_IsRunning.store(true, std::memory_order_relaxed); + m_KeepRunning.store(true, std::memory_order_relaxed); + m_CommandThread = std::thread(&CommandThread::WaitForPacket, this); + } +} + +void CommandThread::Stop() +{ + m_KeepRunning.store(false, std::memory_order_relaxed); +} + +void CommandThread::Join() +{ + m_CommandThread.join(); +} + +bool CommandThread::IsRunning() const +{ + return m_IsRunning.load(std::memory_order_relaxed); +} + +bool CommandThread::StopAfterTimeout(bool stopAfterTimeout) +{ + if (!IsRunning()) + { + m_StopAfterTimeout = stopAfterTimeout; + return true; + } + return false; +} + +}//namespace profiling + +}//namespace armnn
\ No newline at end of file |