mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-28 18:42:26 +00:00
Add TimerDescriptor::setRelative(uint64_t usec)
This commit is contained in:
parent
225f44248c
commit
2df0411b3f
@ -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
|
||||
|
@ -24,6 +24,7 @@ public:
|
||||
|
||||
void reset() const;
|
||||
void drain() const;
|
||||
void setRelative(uint64_t usec) const;
|
||||
void setRelative(Poco::Timespan timespan) const;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user