MCPcopy Create free account
hub / github.com/crayzeewulf/libserial / serialStream2ThreadLoop

Method serialStream2ThreadLoop

test/MultiThreadUnitTests.cpp:94–131  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

92}
93
94void
95MultiThreadUnitTests::serialStream2ThreadLoop()
96{
97 const size_t threadLoopStartTimeMilliseconds = getTimeInMilliSeconds() ;
98 size_t timeElapsedMilliSeconds = 0;
99
100 while (timeElapsedMilliSeconds < timeOutMilliseconds)
101 {
102 //
103 // Write data to the serial port. It should be received by the other
104 // thread.
105 //
106 serialStream2 << writeString2 << std::endl;
107 serialStream2.DrainWriteBuffer() ;
108
109 //
110 // Wait for data to arrive from the other thread
111 //
112 if (serialStream2.IsDataAvailable())
113 {
114 alarm(5) ; // Set a system alarm in case getline() blocks longer than 5 seconds.
115 readString1.clear() ;
116 getline(serialStream2, readString1) ;
117 alarm(0) ; // Deactivate the alarm.
118
119 if(readString1 != writeString1)
120 {
121 const std::lock_guard<std::mutex> lock {mutex} ;
122 failureRate++;
123 }
124 }
125
126 const std::lock_guard<std::mutex> lock {mutex} ;
127 loopCount++;
128
129 timeElapsedMilliSeconds = getTimeInMilliSeconds() - threadLoopStartTimeMilliseconds;
130 }
131}
132
133void
134MultiThreadUnitTests::serialPort1ThreadLoop()

Callers

nothing calls this directly

Calls 2

DrainWriteBufferMethod · 0.45
IsDataAvailableMethod · 0.45

Tested by

no test coverage detected