diff --git a/src/Common/TimerDescriptor.cpp b/src/Common/TimerDescriptor.cpp index 793f7ed1352..086d462eeb2 100644 --- a/src/Common/TimerDescriptor.cpp +++ b/src/Common/TimerDescriptor.cpp @@ -74,17 +74,24 @@ void TimerDescriptor::drain() const } } -void TimerDescriptor::setRelative(Poco::Timespan timespan) const +void TimerDescriptor::setRelative(uint64_t usec) const { + static constexpr uint32_t TIMER_PRECISION = 1e6; + itimerspec spec; spec.it_interval.tv_nsec = 0; spec.it_interval.tv_sec = 0; - spec.it_value.tv_sec = timespan.totalSeconds(); - spec.it_value.tv_nsec = timespan.useconds() * 1000; + spec.it_value.tv_sec = usec / TIMER_PRECISION; + spec.it_value.tv_nsec = (usec % TIMER_PRECISION) * 1'000; if (-1 == timerfd_settime(timer_fd, 0 /*relative timer */, &spec, nullptr)) throwFromErrno("Cannot set time for timer_fd", ErrorCodes::CANNOT_SET_TIMER_PERIOD); } +void TimerDescriptor::setRelative(Poco::Timespan timespan) const +{ + setRelative(timespan.totalMicroseconds()); +} + } #endif diff --git a/src/Common/TimerDescriptor.h b/src/Common/TimerDescriptor.h index 30a610f37f0..8ca69344b53 100644 --- a/src/Common/TimerDescriptor.h +++ b/src/Common/TimerDescriptor.h @@ -24,6 +24,7 @@ public: void reset() const; void drain() const; + void setRelative(uint64_t usec) const; void setRelative(Poco::Timespan timespan) const; };