26#include <sys/timerfd.h>
37static void msec2tspec(
int msec,
struct timespec *ts)
40 ts->tv_sec = msec / 1000;
41 ts->tv_nsec = (msec % 1000) * 1000000;
81 if (timeout < 0 || period < 0) {
86 fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK | TFD_CLOEXEC);
90 if (_uev_watcher_init(ctx, w, UEV_TIMER_TYPE, cb, arg, fd,
UEV_READ))
124 if (timeout < 0 || period < 0) {
132 if (!timeout && !period)
139 w->u.t.timeout = timeout;
140 w->u.t.period = period;
142 if (w->
ctx->running) {
143 struct itimerspec time;
145 msec2tspec(timeout, &time.it_value);
146 msec2tspec(period, &time.it_interval);
147 if (timerfd_settime(w->
fd, 0, &time, NULL) < 0)
151 return _uev_watcher_start(w);
168 _uev_watcher_stop(w);
181 if (!_uev_watcher_active(w))
184 if (_uev_watcher_stop(w))
int uev_timer_start(uev_t *w)
int uev_timer_stop(uev_t *w)
int uev_timer_init(uev_ctx_t *ctx, uev_t *w, uev_cb_t *cb, void *arg, int timeout, int period)
int uev_timer_set(uev_t *w, int timeout, int period)
void uev_cb_t(uev_t *w, void *arg, int events)