1 // 2 // Copyright © 2019 Arm Ltd and Contributors. All rights reserved. 3 // SPDX-License-Identifier: MIT 4 // 5 6 #pragma once 7 8 #include "IProfilingConnection.hpp" 9 #include <common/include/PacketVersionResolver.hpp> 10 11 #include <common/include/CommandHandlerRegistry.hpp> 12 13 #include <atomic> 14 #if !defined(ARMNN_DISABLE_THREADS) 15 #include <thread> 16 #endif 17 18 namespace arm 19 { 20 21 namespace pipe 22 { 23 24 class CommandHandler 25 { 26 public: CommandHandler(uint32_t timeout,bool stopAfterTimeout,arm::pipe::CommandHandlerRegistry & commandHandlerRegistry,arm::pipe::PacketVersionResolver & packetVersionResolver)27 CommandHandler(uint32_t timeout, 28 bool stopAfterTimeout, 29 arm::pipe::CommandHandlerRegistry& commandHandlerRegistry, 30 arm::pipe::PacketVersionResolver& packetVersionResolver) 31 : m_Timeout(timeout), 32 m_StopAfterTimeout(stopAfterTimeout), 33 m_IsRunning(false), 34 m_KeepRunning(false), 35 #if !defined(ARMNN_DISABLE_THREADS) 36 m_CommandThread(), 37 #endif 38 m_CommandHandlerRegistry(commandHandlerRegistry), 39 m_PacketVersionResolver(packetVersionResolver) 40 {} ~CommandHandler()41 ~CommandHandler() { Stop(); } 42 SetTimeout(uint32_t timeout)43 void SetTimeout(uint32_t timeout) { m_Timeout.store(timeout); } SetStopAfterTimeout(bool stopAfterTimeout)44 void SetStopAfterTimeout(bool stopAfterTimeout) { m_StopAfterTimeout.store(stopAfterTimeout); } 45 void Start(IProfilingConnection& profilingConnection); 46 void Stop(); IsRunning() const47 bool IsRunning() const { return m_IsRunning.load(); } 48 49 private: 50 void HandleCommands(IProfilingConnection& profilingConnection); 51 52 std::atomic<uint32_t> m_Timeout; 53 std::atomic<bool> m_StopAfterTimeout; 54 std::atomic<bool> m_IsRunning; 55 std::atomic<bool> m_KeepRunning; 56 #if !defined(ARMNN_DISABLE_THREADS) 57 std::thread m_CommandThread; 58 #endif 59 60 arm::pipe::CommandHandlerRegistry& m_CommandHandlerRegistry; 61 arm::pipe::PacketVersionResolver& m_PacketVersionResolver; 62 }; 63 64 } // namespace pipe 65 66 } // namespace arm 67