From 3896b47a3532aadcde43a3e7fed760a0f4a29e6b Mon Sep 17 00:00:00 2001 From: Sadik Armagan Date: Mon, 10 Feb 2020 12:24:15 +0000 Subject: IVGCVSW-4328 BufferManager running out of buffers crashes application * Refactored SendCounterPacket classes, separated SendCounterPacket from Send thread * Created ISendThread.hpp, IConsumer, SendThread.hpp and SendThread.cpp * Injected IConsumer to BufferManager to notify SendThread when packet is ready to read Signed-off-by: Sadik Armagan Change-Id: I80f0bb8b8401c6bfd1611f7760217c6fe35d7ad8 --- src/profiling/SendThread.hpp | 75 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/profiling/SendThread.hpp (limited to 'src/profiling/SendThread.hpp') diff --git a/src/profiling/SendThread.hpp b/src/profiling/SendThread.hpp new file mode 100644 index 0000000000..af1a72bce5 --- /dev/null +++ b/src/profiling/SendThread.hpp @@ -0,0 +1,75 @@ +// +// Copyright © 2020 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#pragma once + +#include "IBufferManager.hpp" +#include "IConsumer.hpp" +#include "ICounterDirectory.hpp" +#include "ISendCounterPacket.hpp" +#include "ISendThread.hpp" +#include "IProfilingConnection.hpp" +#include "ProfilingStateMachine.hpp" +#include "ProfilingUtils.hpp" + +#include +#include +#include +#include +#include + +namespace armnn +{ + +namespace profiling +{ + +class SendThread : public ISendThread, public IConsumer +{ +public: + SendThread(ProfilingStateMachine& profilingStateMachine, + IBufferManager& buffer, ISendCounterPacket& sendCounterPacket, int timeout= 1000); + ~SendThread() + { + // Don't rethrow when destructing the object + Stop(false); + } + void Start(IProfilingConnection& profilingConnection) override; + + void Stop(bool rethrowSendThreadExceptions = true) override; + + void SetReadyToRead() override; + + bool IsRunning() { return m_IsRunning.load(); } + + bool WaitForPacketSent(uint32_t timeout); + +private: + void Send(IProfilingConnection& profilingConnection); + + void FlushBuffer(IProfilingConnection& profilingConnection, bool notifyWatchers = true); + + ProfilingStateMachine& m_StateMachine; + IBufferManager& m_BufferManager; + ISendCounterPacket& m_SendCounterPacket; + int m_Timeout; + std::mutex m_WaitMutex; + std::condition_variable m_WaitCondition; + std::thread m_SendThread; + std::atomic m_IsRunning; + std::atomic m_KeepRunning; + // m_ReadyToRead will be protected by m_WaitMutex + bool m_ReadyToRead; + // m_PacketSent will be protected by m_PacketSentWaitMutex + bool m_PacketSent; + std::exception_ptr m_SendThreadException; + std::mutex m_PacketSentWaitMutex; + std::condition_variable m_PacketSentWaitCondition; + +}; + +} // namespace profiling + +} // namespace armnn -- cgit v1.2.1