aboutsummaryrefslogtreecommitdiff
path: root/src/profiling/SendCounterPacket.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/profiling/SendCounterPacket.cpp')
-rw-r--r--src/profiling/SendCounterPacket.cpp36
1 files changed, 30 insertions, 6 deletions
diff --git a/src/profiling/SendCounterPacket.cpp b/src/profiling/SendCounterPacket.cpp
index 5badea9d83..5128331c46 100644
--- a/src/profiling/SendCounterPacket.cpp
+++ b/src/profiling/SendCounterPacket.cpp
@@ -936,6 +936,8 @@ void SendCounterPacket::Start(IProfilingConnection& profilingConnection)
// no need for a mutex as the send thread can not be running at this point
m_ReadyToRead = false;
+ m_PacketSent = false;
+
// Start the send thread
m_SendThread = std::thread(&SendCounterPacket::Send, this, std::ref(profilingConnection));
}
@@ -1016,15 +1018,20 @@ void SendCounterPacket::Send(IProfilingConnection& profilingConnection)
{
std::unique_lock<std::mutex> lock(m_WaitMutex);
- m_WaitCondition.wait_for(lock, std::chrono::milliseconds(m_Timeout), [&]{ return m_ReadyToRead; });
-
+ bool timeout = m_WaitCondition.wait_for(lock,
+ std::chrono::milliseconds(m_Timeout),
+ [&]{ return m_ReadyToRead; });
+ // If we get notified we need to flush the buffer again
+ if(timeout)
+ {
+ // Otherwise if we just timed out don't flush the buffer
+ continue;
+ }
//reset condition variable predicate for next use
m_ReadyToRead = false;
}
// Wait condition lock scope - End
-
- // Do not flush the buffer again
- continue;
+ break;
case ProfilingState::Active:
default:
// Wait condition lock scope - Begin
@@ -1103,15 +1110,32 @@ void SendCounterPacket::FlushBuffer(IProfilingConnection& profilingConnection, b
// Get the next available readable buffer
packetBuffer = m_BufferManager.GetReadableBuffer();
}
-
// Check whether at least a packet has been sent
if (packetsSent && notifyWatchers)
{
+ // Wait for the parent thread to release its mutex if necessary
+ {
+ std::lock_guard<std::mutex> lck(m_PacketSentWaitMutex);
+ m_PacketSent = true;
+ }
// Notify to any watcher that something has been sent
m_PacketSentWaitCondition.notify_one();
}
}
+bool SendCounterPacket::WaitForPacketSent(uint32_t timeout = 1000)
+{
+ std::unique_lock<std::mutex> lock(m_PacketSentWaitMutex);
+ // Blocks until notified that at least a packet has been sent or until timeout expires.
+ bool timedOut = m_PacketSentWaitCondition.wait_for(lock,
+ std::chrono::milliseconds(timeout),
+ [&] { return m_PacketSent; });
+
+ m_PacketSent = false;
+
+ return timedOut;
+}
+
} // namespace profiling
} // namespace armnn