Skip to content

Commit b7a1661

Browse files
Don't yield in SlowCounter when catching up
1 parent 81c61a0 commit b7a1661

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

tests/components/SlowCounter.h

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,29 @@ class SlowCounter final : public Component
4949

5050
void Process_( SignalBus&, SignalBus& outputs ) override
5151
{
52-
auto start = std::chrono::high_resolution_clock::now();
52+
_start = std::chrono::high_resolution_clock::now();
5353

5454
outputs.SetValue( 0, _count++ );
5555

56-
std::chrono::duration<double, std::micro> elapsedMs;
57-
do
56+
if ( _waitMs <= 0 )
5857
{
59-
std::this_thread::yield();
60-
elapsedMs = std::chrono::high_resolution_clock::now() - start;
61-
} while ( elapsedMs.count() < _waitMs );
62-
63-
_waitMs = 1000.0 - ( elapsedMs.count() - _waitMs );
58+
_waitMs += 1000.0;
59+
}
60+
else
61+
{
62+
do
63+
{
64+
std::this_thread::yield();
65+
_elapsedMs = std::chrono::high_resolution_clock::now() - _start;
66+
} while ( _elapsedMs.count() < _waitMs );
67+
68+
_waitMs = 1000.0 - ( _elapsedMs.count() - _waitMs );
69+
}
6470
}
6571

6672
private:
73+
std::chrono::high_resolution_clock::time_point _start;
74+
std::chrono::duration<double, std::micro> _elapsedMs;
6775
int _count;
6876
double _waitMs = 1000.0;
6977
};

0 commit comments

Comments
 (0)