aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFinn Williams <Finn.Williams@arm.com>2019-11-29 13:56:33 +0000
committerFinn Williams <Finn.Williams@arm.com>2019-12-04 14:31:41 +0000
commit109c05bc985d25f513444a7caa1e54557ef0f3c0 (patch)
tree59b67e3fff31d6d23bb94b235a6463dfcf91a94d
parent73ae7fa28d05babde16fa232c1d823b35c893e3e (diff)
downloadarmnn-109c05bc985d25f513444a7caa1e54557ef0f3c0.tar.gz
IVGCVSW-4118 Change the SendCounterPacket send thread to use do while
Signed-off-by: Finn Williams <Finn.Williams@arm.com> Change-Id: I702fdc941e29ddcb31f54513e0a7dc642f0f4685
-rw-r--r--src/profiling/SendCounterPacket.cpp6
-rw-r--r--src/profiling/test/SendCounterPacketTests.cpp31
2 files changed, 11 insertions, 26 deletions
diff --git a/src/profiling/SendCounterPacket.cpp b/src/profiling/SendCounterPacket.cpp
index e3a9b77f41..a9846c9f06 100644
--- a/src/profiling/SendCounterPacket.cpp
+++ b/src/profiling/SendCounterPacket.cpp
@@ -974,8 +974,8 @@ void SendCounterPacket::Stop(bool rethrowSendThreadExceptions)
void SendCounterPacket::Send(IProfilingConnection& profilingConnection)
{
- // Keep the sending procedure looping until the thread is signalled to stop
- while (m_KeepRunning.load())
+ // Run once and keep the sending procedure looping until the thread is signalled to stop
+ do
{
// Check the current state of the profiling service
ProfilingState currentState = m_StateMachine.GetCurrentState();
@@ -1054,7 +1054,7 @@ void SendCounterPacket::Send(IProfilingConnection& profilingConnection)
// Send all the available packets in the buffer
FlushBuffer(profilingConnection);
- }
+ } while (m_KeepRunning.load());
// Ensure that all readable data got written to the profiling connection before the thread is stopped
// (do not notify any watcher in this case, as this is just to wrap up things before shutting down the send thread)
diff --git a/src/profiling/test/SendCounterPacketTests.cpp b/src/profiling/test/SendCounterPacketTests.cpp
index 740ea33c9a..b4564fec29 100644
--- a/src/profiling/test/SendCounterPacketTests.cpp
+++ b/src/profiling/test/SendCounterPacketTests.cpp
@@ -1793,8 +1793,6 @@ BOOST_AUTO_TEST_CASE(SendThreadTest0)
sendCounterPacket.Start(mockProfilingConnection);
BOOST_CHECK(sendCounterPacket.IsRunning());
- std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS));
-
sendCounterPacket.Stop();
BOOST_CHECK(!sendCounterPacket.IsRunning());
}
@@ -1899,7 +1897,7 @@ BOOST_AUTO_TEST_CASE(SendThreadTest1)
sendCounterPacket.SetReadyToRead();
- // To test an exact value of the "read size" in the mock buffer, wait two seconds to allow the send thread to
+ // To test an exact value of the "read size" in the mock buffer, wait to allow the send thread to
// read all what's remaining in the buffer
std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS));
@@ -2022,7 +2020,7 @@ BOOST_AUTO_TEST_CASE(SendThreadTest2)
sendCounterPacket.SetReadyToRead();
- // To test an exact value of the "read size" in the mock buffer, wait two seconds to allow the send thread to
+ // To test an exact value of the "read size" in the mock buffer, wait to allow the send thread to
// read all what's remaining in the buffer
std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS));
@@ -2346,10 +2344,6 @@ BOOST_AUTO_TEST_CASE(SendThreadSendStreamMetadataPacket1)
sendCounterPacket.Start(mockProfilingConnection);
// The profiling state is set to "Uninitialized", so the send thread should throw an exception
-
- // Wait a bit to make sure that the send thread is properly started
- std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS));
-
BOOST_CHECK_THROW(sendCounterPacket.Stop(), armnn::RuntimeException);
}
@@ -2364,10 +2358,6 @@ BOOST_AUTO_TEST_CASE(SendThreadSendStreamMetadataPacket2)
sendCounterPacket.Start(mockProfilingConnection);
// The profiling state is set to "NotConnected", so the send thread should throw an exception
-
- // Wait a bit to make sure that the send thread is properly started
- std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS));
-
BOOST_CHECK_THROW(sendCounterPacket.Stop(), armnn::RuntimeException);
}
@@ -2387,10 +2377,7 @@ BOOST_AUTO_TEST_CASE(SendThreadSendStreamMetadataPacket3)
sendCounterPacket.Start(mockProfilingConnection);
// The profiling state is set to "WaitingForAck", so the send thread should send a Stream Metadata packet
-
- // Wait for a bit to make sure that we get the packet
- std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS));
-
+ // Wait for sendCounterPacket to join
BOOST_CHECK_NO_THROW(sendCounterPacket.Stop());
// Check that the buffer contains one Stream Metadata packet
@@ -2415,10 +2402,10 @@ BOOST_AUTO_TEST_CASE(SendThreadSendStreamMetadataPacket4)
sendCounterPacket.Start(mockProfilingConnection);
// The profiling state is set to "WaitingForAck", so the send thread should send a Stream Metadata packet
+ // Wait for sendCounterPacket to join
+ sendCounterPacket.Stop();
- // Wait for a bit to make sure that we get the packet
- std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS));
-
+ sendCounterPacket.Start(mockProfilingConnection);
// Check that the profiling state is still "WaitingForAck"
BOOST_TEST((profilingStateMachine.GetCurrentState() == ProfilingState::WaitingForAck));
@@ -2432,8 +2419,8 @@ BOOST_AUTO_TEST_CASE(SendThreadSendStreamMetadataPacket4)
// Try triggering a new buffer read
sendCounterPacket.SetReadyToRead();
- // Wait for a bit to make sure that we get the packet
- std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS));
+ // Wait for sendCounterPacket to join
+ BOOST_CHECK_NO_THROW(sendCounterPacket.Stop());
// Check that the profiling state is still "WaitingForAck"
BOOST_TEST((profilingStateMachine.GetCurrentState() == ProfilingState::WaitingForAck));
@@ -2441,8 +2428,6 @@ BOOST_AUTO_TEST_CASE(SendThreadSendStreamMetadataPacket4)
// Check that the buffer contains one Stream Metadata packet
BOOST_TEST(writtenData.size() == 1);
BOOST_TEST(writtenData[0] == streamMetadataPacketsize);
-
- BOOST_CHECK_NO_THROW(sendCounterPacket.Stop());
}
BOOST_AUTO_TEST_SUITE_END()