aboutsummaryrefslogtreecommitdiff
path: root/src/profiling/CommandHandler.cpp
diff options
context:
space:
mode:
authorMatteo Martincigh <matteo.martincigh@arm.com>2019-10-04 17:01:07 +0100
committerMatteo Martincigh <matteo.martincigh@arm.com>2019-10-07 10:08:44 +0000
commit8a837179ad883e9b5dd982a25cc5e94f245f79ed (patch)
tree08c798ca632850e0f339ab6b9d50adedd0701c75 /src/profiling/CommandHandler.cpp
parent88813936232bc47fc7768800c6895191585570e8 (diff)
downloadarmnn-8a837179ad883e9b5dd982a25cc5e94f245f79ed.tar.gz
IVGCVSW-3937 Rename CommandThread to CommandHandler
* Renamed files, class name and methods accordingly * Updated unit tests accordingly Signed-off-by: Matteo Martincigh <matteo.martincigh@arm.com> Change-Id: Ifb88aa61edb93b852a07b1bd59bd259213677b44
Diffstat (limited to 'src/profiling/CommandHandler.cpp')
-rw-r--r--src/profiling/CommandHandler.cpp85
1 files changed, 85 insertions, 0 deletions
diff --git a/src/profiling/CommandHandler.cpp b/src/profiling/CommandHandler.cpp
new file mode 100644
index 0000000000..5eddfd5ec3
--- /dev/null
+++ b/src/profiling/CommandHandler.cpp
@@ -0,0 +1,85 @@
+//
+// Copyright © 2019 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include "CommandHandler.hpp"
+
+namespace armnn
+{
+
+namespace profiling
+{
+
+void CommandHandler::Start(IProfilingConnection& profilingConnection)
+{
+ if (IsRunning())
+ {
+ return;
+ }
+
+ m_IsRunning.store(true, std::memory_order_relaxed);
+ m_KeepRunning.store(true, std::memory_order_relaxed);
+ m_CommandThread = std::thread(&CommandHandler::HandleCommands, this, std::ref(profilingConnection));
+}
+
+void CommandHandler::Stop()
+{
+ m_KeepRunning.store(false, std::memory_order_relaxed);
+
+ if (m_CommandThread.joinable())
+ {
+ m_CommandThread.join();
+ }
+}
+
+bool CommandHandler::IsRunning() const
+{
+ return m_IsRunning.load(std::memory_order_relaxed);
+}
+
+void CommandHandler::SetTimeout(uint32_t timeout)
+{
+ m_Timeout.store(timeout, std::memory_order_relaxed);
+}
+
+void CommandHandler::SetStopAfterTimeout(bool stopAfterTimeout)
+{
+ m_StopAfterTimeout.store(stopAfterTimeout, std::memory_order_relaxed);
+}
+
+void CommandHandler::HandleCommands(IProfilingConnection& profilingConnection)
+{
+ do
+ {
+ try
+ {
+ Packet packet = profilingConnection.ReadPacket(m_Timeout);
+ Version version = m_PacketVersionResolver.ResolvePacketVersion(packet.GetPacketId());
+
+ CommandHandlerFunctor* commandHandlerFunctor =
+ m_CommandHandlerRegistry.GetFunctor(packet.GetPacketId(), version.GetEncodedValue());
+ BOOST_ASSERT(commandHandlerFunctor);
+ commandHandlerFunctor->operator()(packet);
+ }
+ catch (const armnn::TimeoutException&)
+ {
+ if (m_StopAfterTimeout)
+ {
+ m_KeepRunning.store(false, std::memory_order_relaxed);
+ }
+ }
+ catch (...)
+ {
+ // Might want to differentiate the errors more
+ m_KeepRunning.store(false, std::memory_order_relaxed);
+ }
+ }
+ while (m_KeepRunning.load(std::memory_order_relaxed));
+
+ m_IsRunning.store(false, std::memory_order_relaxed);
+}
+
+} // namespace profiling
+
+} // namespace armnn