22 #include <sys/timerfd.h> 35 int r =
read(
_fd, &nevents,
sizeof(nevents));
57 _fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC|TFD_NONBLOCK);
77 struct itimerspec spec = { };
82 if (timerfd_settime(
_fd, 0, &spec,
nullptr) < 0) {
91 uint32_t timeout_usec)
98 !_poller.register_pollable(p, POLLIN)) {
103 _timers.push_back(p);
111 auto it = std::find(_timers.begin(), _timers.end(), p);
112 if (it == _timers.end()) {
116 return (*it)->adjust_timer(timeout_usec);
125 for (
auto it = _timers.begin(); it != _timers.end(); it++) {
129 _poller.unregister_pollable(p);
141 while (!_should_exit) {
147 _should_exit =
false;
bool adjust_timer(uint32_t timeout_usec)
bool adjust_timer(TimerPollable *p, uint32_t timeout_usec)
AP_HAL::Device::PeriodicCb PeriodicCb
void on_can_read() override
ssize_t read(int fd, void *buf, size_t count)
POSIX read count bytes from *buf to fileno fd.
bool setup_timer(uint32_t timeout_usec)
int close(int fileno)
POSIX Close a file with fileno handel.
TimerPollable(PeriodicCb cb, WrapperCb *wrapper)
TimerPollable * add_timer(TimerPollable::PeriodicCb cb, TimerPollable::WrapperCb *wrapper, uint32_t timeout_usec)