Lines Matching defs:timer

33 #include "timer.h"
36 libinput_timer_init(struct libinput_timer *timer,
42 timer->libinput = libinput;
43 timer->timer_name = safe_strdup(timer_name);
44 timer->timer_func = timer_func;
45 timer->timer_func_data = timer_func_data;
47 ratelimit_init(&libinput->timer.expiry_in_past_limit,
52 libinput_timer_destroy(struct libinput_timer *timer)
54 if (timer->link.prev != NULL && timer->link.next != NULL &&
55 !list_empty(&timer->link)) {
56 log_bug_libinput(timer->libinput,
57 "timer: %s has not been cancelled\n",
58 timer->timer_name);
59 assert(!"timer not cancelled");
61 free(timer->timer_name);
68 struct libinput_timer *timer;
72 list_for_each(timer, &libinput->timer.list, link) {
73 if (timer->expire < earliest_expire)
74 earliest_expire = timer->expire;
82 r = timerfd_settime(libinput->timer.fd, TFD_TIMER_ABSTIME, &its, NULL);
84 log_error(libinput, "timer: timerfd_settime error: %s\n", strerror(errno));
86 libinput->timer.next_expiry = earliest_expire;
90 libinput_timer_set_flags(struct libinput_timer *timer,
97 uint64_t now = libinput_now(timer->libinput);
101 log_bug_client_ratelimit(timer->libinput,
102 &timer->libinput->timer.expiry_in_past_limit,
103 "timer %s: scheduled expiry is in the past (-%dms), your system is too slow\n",
104 timer->timer_name,
107 log_bug_libinput(timer->libinput,
108 "timer %s: offset more than 5s, now %d expire %d\n",
109 timer->timer_name,
116 if (!timer->expire)
117 list_insert(&timer->libinput->timer.list, &timer->link);
119 timer->expire = expire;
120 libinput_timer_arm_timer_fd(timer->libinput);
124 libinput_timer_set(struct libinput_timer *timer, uint64_t expire)
126 libinput_timer_set_flags(timer, expire, TIMER_FLAG_NONE);
130 libinput_timer_cancel(struct libinput_timer *timer)
132 if (!timer->expire)
135 timer->expire = 0;
136 list_remove(&timer->link);
137 libinput_timer_arm_timer_fd(timer->libinput);
143 struct libinput_timer *timer;
146 list_for_each_safe(timer, &libinput->timer.list, link) {
147 if (timer->expire == 0)
150 if (timer->expire <= now) {
151 /* Clear the timer before calling timer_func,
153 libinput_timer_cancel(timer);
154 timer->timer_func(now, timer->timer_func_data);
159 * allows removing one (our) timer per timer_func.
160 * But the timer func may trigger another unrelated
161 * timer to be cancelled and removed, causing a
177 r = read(libinput->timer.fd, &discard, sizeof(discard));
180 "timer: error %d reading from timerfd (%s)",
194 libinput->timer.fd = timerfd_create(CLOCK_MONOTONIC,
196 if (libinput->timer.fd < 0)
199 list_init(&libinput->timer.list);
201 libinput->timer.source = libinput_add_fd(libinput,
202 libinput->timer.fd,
205 if (!libinput->timer.source) {
206 close(libinput->timer.fd);
217 if (!list_empty(&libinput->timer.list)) {
220 list_for_each(t, &libinput->timer.list, link) {
222 "timer: %s still present on shutdown\n",
228 /* All timer users should have destroyed their timers now */
229 assert(list_empty(&libinput->timer.list));
231 libinput_remove_source(libinput, libinput->timer.source);
232 close(libinput->timer.fd);
237 * timer expiry *and* a later input event waiting in the pipe. We cannot
238 * guarantee that we read the timer expiry first, so this hook exists to
241 * Assume 'now' is the current time check if there is a current timer expiry
242 * before this time. If so, trigger the timer func.
247 if (libinput->timer.next_expiry == 0 ||
248 libinput->timer.next_expiry > now)