| 226 | } |
| 227 | |
| 228 | void SendThread::FlushBuffer(IProfilingConnection& profilingConnection, bool notifyWatchers) |
| 229 | { |
| 230 | // Get the first available readable buffer |
| 231 | IPacketBufferPtr packetBuffer = m_BufferManager.GetReadableBuffer(); |
| 232 | |
| 233 | // Initialize the flag that indicates whether at least a packet has been sent |
| 234 | bool packetsSent = false; |
| 235 | |
| 236 | while (packetBuffer != nullptr) |
| 237 | { |
| 238 | // Get the data to send from the buffer |
| 239 | const unsigned char* readBuffer = packetBuffer->GetReadableData(); |
| 240 | unsigned int readBufferSize = packetBuffer->GetSize(); |
| 241 | |
| 242 | if (readBuffer == nullptr || readBufferSize == 0) |
| 243 | { |
| 244 | // Nothing to send, get the next available readable buffer and continue |
| 245 | m_BufferManager.MarkRead(packetBuffer); |
| 246 | packetBuffer = m_BufferManager.GetReadableBuffer(); |
| 247 | |
| 248 | continue; |
| 249 | } |
| 250 | |
| 251 | // Check that the profiling connection is open, silently drop the data and continue if it's closed |
| 252 | if (profilingConnection.IsOpen()) |
| 253 | { |
| 254 | // Write a packet to the profiling connection. Silently ignore any write error and continue |
| 255 | profilingConnection.WritePacket(readBuffer, arm::pipe::numeric_cast<uint32_t>(readBufferSize)); |
| 256 | |
| 257 | // Set the flag that indicates whether at least a packet has been sent |
| 258 | packetsSent = true; |
| 259 | } |
| 260 | |
| 261 | // Mark the packet buffer as read |
| 262 | m_BufferManager.MarkRead(packetBuffer); |
| 263 | |
| 264 | // Get the next available readable buffer |
| 265 | packetBuffer = m_BufferManager.GetReadableBuffer(); |
| 266 | } |
| 267 | // Check whether at least a packet has been sent |
| 268 | if (packetsSent && notifyWatchers) |
| 269 | { |
| 270 | // Wait for the parent thread to release its mutex if necessary |
| 271 | { |
| 272 | #if !defined(ARMNN_DISABLE_THREADS) |
| 273 | std::lock_guard<std::mutex> lck(m_PacketSentWaitMutex); |
| 274 | #endif |
| 275 | m_PacketSent = true; |
| 276 | } |
| 277 | // Notify to any watcher that something has been sent |
| 278 | #if !defined(ARMNN_DISABLE_THREADS) |
| 279 | m_PacketSentWaitCondition.notify_one(); |
| 280 | #endif |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | bool SendThread::WaitForPacketSent(uint32_t timeout = 1000) |
| 285 | { |
nothing calls this directly
no test coverage detected