| 122 | } |
| 123 | |
| 124 | void SendThread::Send(IProfilingConnection& profilingConnection) |
| 125 | { |
| 126 | // Run once and keep the sending procedure looping until the thread is signalled to stop |
| 127 | do |
| 128 | { |
| 129 | // Check the current state of the profiling service |
| 130 | ProfilingState currentState = m_StateMachine.GetCurrentState(); |
| 131 | switch (currentState) |
| 132 | { |
| 133 | case ProfilingState::Uninitialised: |
| 134 | case ProfilingState::NotConnected: |
| 135 | |
| 136 | // The send thread cannot be running when the profiling service is uninitialized or not connected, |
| 137 | // stop the thread immediately |
| 138 | m_KeepRunning.store(false); |
| 139 | m_IsRunning.store(false); |
| 140 | |
| 141 | // An exception should be thrown here, save it to be rethrown later from the main thread so that |
| 142 | // it can be caught by the consumer |
| 143 | m_SendThreadException = |
| 144 | std::make_exception_ptr(arm::pipe::ProfilingException( |
| 145 | "The send thread should not be running with the profiling service not yet initialized or connected")); |
| 146 | |
| 147 | return; |
| 148 | case ProfilingState::WaitingForAck: |
| 149 | |
| 150 | // Send out a StreamMetadata packet and wait for the profiling connection to be acknowledged. |
| 151 | // When a ConnectionAcknowledged packet is received, the profiling service state will be automatically |
| 152 | // updated by the command handler |
| 153 | |
| 154 | // Prepare a StreamMetadata packet and write it to the Counter Stream buffer |
| 155 | m_SendCounterPacket.SendStreamMetaDataPacket(); |
| 156 | |
| 157 | // Flush the buffer manually to send the packet |
| 158 | FlushBuffer(profilingConnection); |
| 159 | |
| 160 | // Wait for a connection ack from the remote server. We should expect a response within timeout value. |
| 161 | // If not, drop back to the start of the loop and detect somebody closing the thread. Then send the |
| 162 | // StreamMetadata again. |
| 163 | |
| 164 | // Wait condition lock scope - Begin |
| 165 | { |
| 166 | #if !defined(ARMNN_DISABLE_THREADS) |
| 167 | std::unique_lock<std::mutex> lock(m_WaitMutex); |
| 168 | |
| 169 | bool timeout = m_WaitCondition.wait_for(lock, |
| 170 | std::chrono::milliseconds(std::max(m_Timeout, 1000)), |
| 171 | [&]{ return m_ReadyToRead; }); |
| 172 | // If we get notified we need to flush the buffer again |
| 173 | if (timeout) |
| 174 | { |
| 175 | // Otherwise if we just timed out don't flush the buffer |
| 176 | continue; |
| 177 | } |
| 178 | #endif |
| 179 | //reset condition variable predicate for next use |
| 180 | m_ReadyToRead = false; |
| 181 | } |
nothing calls this directly
no test coverage detected