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

Method serialStream1ThreadLoop

test/MultiThreadUnitTests.cpp:55–92  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53}
54
55void
56MultiThreadUnitTests::serialStream1ThreadLoop()
57{
58 size_t threadLoopStartTimeMilliseconds = getTimeInMilliSeconds() ;
59 size_t timeElapsedMilliSeconds = 0;
60
61 while (timeElapsedMilliSeconds < timeOutMilliseconds)
62 {
63 //
64 // Write data to the serial port. It should be received by the other
65 // thread.
66 //
67 serialStream1 << writeString1 << std::endl;
68 serialStream1.DrainWriteBuffer() ;
69
70 //
71 // Wait for data to arrive from the other thread
72 //
73 if (serialStream1.IsDataAvailable())
74 {
75 alarm(5) ; // Set a system alarm in case getline() blocks longer than 5 seconds.
76 readString2.clear() ;
77 getline(serialStream1, readString2) ;
78 alarm(0) ; // Deactivate the alarm.
79
80 if(readString2 != writeString2)
81 {
82 const std::lock_guard<std::mutex> lock {mutex} ;
83 failureRate++;
84 }
85 }
86
87 const std::lock_guard<std::mutex> lock {mutex} ;
88 loopCount++;
89
90 timeElapsedMilliSeconds = getTimeInMilliSeconds() - threadLoopStartTimeMilliseconds;
91 }
92}
93
94void
95MultiThreadUnitTests::serialStream2ThreadLoop()

Callers

nothing calls this directly

Calls 2

DrainWriteBufferMethod · 0.45
IsDataAvailableMethod · 0.45

Tested by

no test coverage detected