diff options
-rw-r--r-- | src/profiling/FileOnlyProfilingConnection.cpp | 21 | ||||
-rw-r--r-- | src/profiling/FileOnlyProfilingConnection.hpp | 4 | ||||
-rw-r--r-- | src/profiling/test/FileOnlyProfilingDecoratorTests.cpp | 4 |
3 files changed, 19 insertions, 10 deletions
diff --git a/src/profiling/FileOnlyProfilingConnection.cpp b/src/profiling/FileOnlyProfilingConnection.cpp index b32ae49911..004e27d30a 100644 --- a/src/profiling/FileOnlyProfilingConnection.cpp +++ b/src/profiling/FileOnlyProfilingConnection.cpp @@ -69,7 +69,11 @@ void FileOnlyProfilingConnection::SendConnectionAck() std::cout << "Sending connection acknowledgement." << std::endl; } std::unique_ptr<unsigned char[]> uniqueNullPtr = nullptr; - m_PacketQueue.push(Packet(0x10000, 0, uniqueNullPtr)); + { + std::lock_guard<std::mutex> lck(m_PacketAvailableMutex); + m_PacketQueue.push(Packet(0x10000, 0, uniqueNullPtr)); + } + m_ConditionPacketAvailable.notify_one(); } bool FileOnlyProfilingConnection::SendCounterSelectionPacket() @@ -94,7 +98,11 @@ bool FileOnlyProfilingConnection::SendCounterSelectionPacket() offset += uint16_t_size; } - m_PacketQueue.push(Packet(0x40000, bodySize, uniqueData)); + { + std::lock_guard<std::mutex> lck(m_PacketAvailableMutex); + m_PacketQueue.push(Packet(0x40000, bodySize, uniqueData)); + } + m_ConditionPacketAvailable.notify_one(); return true; } @@ -155,13 +163,10 @@ bool FileOnlyProfilingConnection::WritePacket(const unsigned char* buffer, uint3 Packet FileOnlyProfilingConnection::ReadPacket(uint32_t timeout) { - uint16_t loopCount = 10; - uint32_t timeoutFraction = timeout / loopCount; - while (m_PacketQueue.empty()) + std::unique_lock<std::mutex> lck(m_PacketAvailableMutex); + if (m_PacketQueue.empty()) { - std::this_thread::sleep_for(std::chrono::milliseconds(timeoutFraction)); - --loopCount; - if ((loopCount) == 0) + 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"); } diff --git a/src/profiling/FileOnlyProfilingConnection.hpp b/src/profiling/FileOnlyProfilingConnection.hpp index 12a87a1535..d4477b6883 100644 --- a/src/profiling/FileOnlyProfilingConnection.hpp +++ b/src/profiling/FileOnlyProfilingConnection.hpp @@ -11,6 +11,7 @@ #include "ProfilingUtils.hpp" #include "Runtime.hpp" +#include <condition_variable> #include <fstream> #include <queue> @@ -75,6 +76,9 @@ private: std::vector<uint16_t> m_IdList; std::queue<Packet> m_PacketQueue; TargetEndianness m_Endianness; + + std::mutex m_PacketAvailableMutex; + std::condition_variable m_ConditionPacketAvailable; }; } // namespace profiling diff --git a/src/profiling/test/FileOnlyProfilingDecoratorTests.cpp b/src/profiling/test/FileOnlyProfilingDecoratorTests.cpp index 5524ed4fbf..d4907b6365 100644 --- a/src/profiling/test/FileOnlyProfilingDecoratorTests.cpp +++ b/src/profiling/test/FileOnlyProfilingDecoratorTests.cpp @@ -45,8 +45,8 @@ BOOST_AUTO_TEST_CASE(DumpOutgoingValidFileEndToEnd) profilingService.Update(); profilingService.Update(); - uint32_t timeout = 2000; - uint32_t sleepTime = 50; + uint32_t timeout = 25; // Wait for a maximum of 25mSec + uint32_t sleepTime = 1; // in 1mSec intervals. uint32_t timeSlept = 0; // Give the profiling service sending thread time start executing and send the stream metadata. |