timer: set O_NONBLOCK on the timerfd
authorPeter Hutterer <peter.hutterer@who-t.net>
Thu, 30 Apr 2015 23:09:38 +0000 (09:09 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Thu, 30 Apr 2015 23:09:38 +0000 (09:09 +1000)
Resetting a timerfd empties the data on the fd, so if the timer is reset
between triggering and us reading it, we may block trying to read it.

Since we read events off a device in a loop, a device sending a continuous
flow of events may cause the timer to trigger but delay reading it. If one of
the events cause e.g. the tap timer to be set, the timerfd may be empty at the
time of reading.

Suggested-by: Derek Foreman <derekf@osg.samsung.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
src/timer.c

index 285f75b2a0a83b4d58485704978b0a416beb5fec..114a64963d4daf86f607503f347a1155f9fec6b6 100644 (file)
@@ -122,7 +122,8 @@ libinput_timer_handler(void *data)
 int
 libinput_timer_subsys_init(struct libinput *libinput)
 {
-       libinput->timer.fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC);
+       libinput->timer.fd = timerfd_create(CLOCK_MONOTONIC,
+                                           TFD_CLOEXEC | TFD_NONBLOCK);
        if (libinput->timer.fd < 0)
                return -1;