24 : mState(stopped), mOverruns(0), mTicks(0), mFlags(flags),
55 uint64_t ticks = 0, overruns;
60 bytes = read(mTimerFd, &ticks,
sizeof(ticks));
62 SPDLOG_LOGGER_ERROR(
mSLog,
"Read from timerfd failed");
66 std::this_thread::sleep_until(mNextTick);
68 auto now = IntervalClock::now();
70 while (mNextTick < now) {
71 mNextTick += mTickInterval;
78 mOverruns += overruns;
82 SPDLOG_LOGGER_WARN(
mSLog,
"Timer overrun of {} timesteps at {}", overruns,
84 if (mFlags & Flags::fail_on_overrun) {
85 SPDLOG_LOGGER_ERROR(
mSLog,
"The overrun has made the simulation to fail "
86 "because the flag is active");
93 assert(mState == stopped);
99 auto rt = StartClock::now();
100 auto steady = IntervalClock::now();
106 auto start = mStartAt > StartTimePoint()
107 ? mStartAt.time_since_epoch() - rt.time_since_epoch() +
108 steady.time_since_epoch()
109 : steady.time_since_epoch();
113 struct itimerspec ts = {.it_interval = to_timespec(mTickInterval),
114 .it_value = to_timespec(start)};
116 ret = timerfd_settime(mTimerFd, TFD_TIMER_ABSTIME, &ts, 0);
121 mNextTick = IntervalTimePoint(start) + mTickInterval;
122 mState = State::running;
126 assert(mState == State::running);
130 struct itimerspec ts = {.it_interval = {0, 0}, .it_value = {0, 0}};
132 ret = timerfd_settime(mTimerFd, 0, &ts, 0);
138 mState = State::stopped;