using steady_clock instead of system_clock

This commit is contained in:
Matthias Richter 2017-11-17 14:15:00 +01:00 committed by Mohammad Al-Turany
parent 4351f3df0d
commit 72cdd1e3d7

View File

@ -514,19 +514,19 @@ void FairMQDevice::RunWrapper()
} }
else else
{ {
using Clock = std::chrono::steady_clock;
using TimeScale = std::chrono::microseconds;
const TimeScale::rep period = TimeScale::period::den / fRate;
const auto reftime = Clock::now();
while (CheckCurrentState(RUNNING) && ConditionalRun()) while (CheckCurrentState(RUNNING) && ConditionalRun())
{ {
using TimeScale = std::chrono::microseconds;
static const auto reftime = std::chrono::system_clock::now();
if (fRate > 0.001) { if (fRate > 0.001) {
auto timeSinceRef = std::chrono::duration_cast<TimeScale>(std::chrono::system_clock::now() - reftime); auto timespan = std::chrono::duration_cast<TimeScale>(Clock::now() - reftime).count() - fLastTime;
auto timespan = timeSinceRef.count() - fLastTime;
TimeScale::rep period = static_cast<float>(TimeScale::period::den) / fRate;
if (timespan < period) { if (timespan < period) {
TimeScale sleepfor(period - timespan); TimeScale sleepfor(period - timespan);
std::this_thread::sleep_for(sleepfor); std::this_thread::sleep_for(sleepfor);
} }
fLastTime = std::chrono::duration_cast<TimeScale>(std::chrono::system_clock::now() - reftime).count(); fLastTime = std::chrono::duration_cast<TimeScale>(Clock::now() - reftime).count();
} }
} }