IVGCVSW-4129 Fix thread starvation due to low capture periods
[platform/upstream/armnn.git] / tests / profiling / gatordmock / GatordMockService.hpp
index 10bf884..c3afc33 100644 (file)
@@ -41,6 +41,7 @@ public:
     GatordMockService(armnn::profiling::CommandHandlerRegistry& registry, bool echoPackets)
         : m_HandlerRegistry(registry)
         , m_EchoPackets(echoPackets)
+        , m_CloseReceivingThread(false)
     {
         m_PacketsReceivedCount.store(0, std::memory_order_relaxed);
     }
@@ -69,6 +70,9 @@ public:
     /// Send a connection acknowledged packet back to the client.
     void SendConnectionAck();
 
+    /// Send a request counter directory packet back to the client.
+    void SendRequestCounterDir();
+
     /// Start the thread that will receive all packets and print them nicely to stdout.
     bool LaunchReceivingThread();
 
@@ -83,11 +87,17 @@ public:
     /// command handling code is added.
     void WaitForReceivingThread();
 
+    // @return true only if the receive thread is closed or closing.
+    bool ReceiveThreadRunning()
+    {
+        return !m_CloseReceivingThread.load();
+    }
+
     /// Send the counter list to ArmNN.
     void SendPeriodicCounterSelectionList(uint32_t period, std::vector<uint16_t> counters);
 
     /// Execute the WAIT command from the comamnd file.
-    void WaitCommand(uint timeout);
+    void WaitCommand(uint32_t timeout);
 
     uint32_t GetStreamMetadataVersion()
     {
@@ -114,17 +124,17 @@ private:
 
     armnn::profiling::Packet ReceivePacket();
 
-    bool SendPacket(uint32_t packetFamily, uint32_t packetId, const u_char* data, uint32_t dataLength);
+    bool SendPacket(uint32_t packetFamily, uint32_t packetId, const uint8_t* data, uint32_t dataLength);
 
-    void EchoPacket(PacketDirection direction, u_char* packet, size_t lengthInBytes);
+    void EchoPacket(PacketDirection direction, uint8_t* packet, size_t lengthInBytes);
 
     bool ReadHeader(uint32_t headerAsWords[2]);
 
-    bool ReadFromSocket(u_char* packetData, uint32_t expectedLength);
+    bool ReadFromSocket(uint8_t* packetData, uint32_t expectedLength);
 
-    uint32_t ToUint32(u_char* data, TargetEndianness endianness);
+    uint32_t ToUint32(uint8_t* data, TargetEndianness endianness);
 
-    void InsertU32(uint32_t value, u_char* data, TargetEndianness endianness);
+    void InsertU32(uint32_t value, uint8_t* data, TargetEndianness endianness);
 
     static const uint32_t PIPE_MAGIC = 0x45495434;