From 09ad6f909f25aef02b7f53bba320b534b9260786 Mon Sep 17 00:00:00 2001 From: Finn Williams Date: Thu, 19 Dec 2019 17:05:18 +0000 Subject: IVGCVSW-4229 Fix Intermittent failures in ExternalProfiling * Added a BufferManager.Reset() method to prevent packets being retained after a test * Fixed a bug causing the send thread to wait needlessly before moving to active state * Refactored SendCoundPacketTests and ProfilingTests test helper classes * Fixed issue where WaitForPacketSent could miss a notification and timeout Signed-off-by: Finn Williams Change-Id: I353a652260c2f7dd465baa9e979e22f50f3ca6a7 --- src/profiling/FileOnlyProfilingConnection.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/profiling/FileOnlyProfilingConnection.cpp') diff --git a/src/profiling/FileOnlyProfilingConnection.cpp b/src/profiling/FileOnlyProfilingConnection.cpp index 75862616b9..1db8030313 100644 --- a/src/profiling/FileOnlyProfilingConnection.cpp +++ b/src/profiling/FileOnlyProfilingConnection.cpp @@ -166,13 +166,16 @@ bool FileOnlyProfilingConnection::WritePacket(const unsigned char* buffer, uint3 Packet FileOnlyProfilingConnection::ReadPacket(uint32_t timeout) { std::unique_lock lck(m_PacketAvailableMutex); - if (m_PacketQueue.empty()) + + // Here we are using m_PacketQueue.empty() as a predicate variable + // The conditional variable will wait until packetQueue is not empty or until a timeout + if(!m_ConditionPacketAvailable.wait_for(lck, + std::chrono::milliseconds(timeout), + [&]{return !m_PacketQueue.empty();})) { - if(m_ConditionPacketAvailable.wait_for(lck, std::chrono::milliseconds(timeout)) == std::cv_status::timeout) - { - throw armnn::TimeoutException("Thread has timed out as per requested time limit"); - } + throw armnn::TimeoutException("Thread has timed out as per requested time limit"); } + Packet returnedPacket = std::move(m_PacketQueue.front()); m_PacketQueue.pop(); return returnedPacket; -- cgit v1.2.1