From b27cd9cedfc15c4d8125cea659a1b5cdb5b071cf Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 2 Nov 2019 01:14:40 +0100 Subject: timerfd: use non-blocking mode, fixes dead lock Since we cancel the timers every now and then, there's a (small) chance that one handler cancels a timer that has triggered in the same epoll() iteration. When this happens, read() blocks. Fix by making the timer FDs non-blocking, and simply returning when we read 0 bytes. --- wayland.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'wayland.c') diff --git a/wayland.c b/wayland.c index 3d19c4de..ad8211b7 100644 --- a/wayland.c +++ b/wayland.c @@ -411,6 +411,11 @@ fdm_repeat(struct fdm *fdm, int fd, int events, void *data) return false; } + if (ret == 0) { + /* Cancelled by other handler in *this* epoll() iteration */ + return true; + } + wayl->kbd.repeat.dont_re_repeat = true; for (size_t i = 0; i < expiration_count; i++) input_repeat(wayl, wayl->kbd.repeat.key); @@ -513,7 +518,7 @@ wayl_init(struct fdm *fdm) /* All wayland initialization done - make it so */ wl_display_roundtrip(wayl->display); - wayl->kbd.repeat.fd = timerfd_create(CLOCK_BOOTTIME, TFD_CLOEXEC); + wayl->kbd.repeat.fd = timerfd_create(CLOCK_BOOTTIME, TFD_CLOEXEC | TFD_NONBLOCK); if (wayl->kbd.repeat.fd == -1) { LOG_ERRNO("failed to create keyboard repeat timer FD"); goto out; -- cgit v1.3