aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2019-11-02 00:14:40 +0000
committerDaniel Eklöf <daniel@ekloef.se>2019-11-02 00:14:40 +0000
commitb27cd9cedfc15c4d8125cea659a1b5cdb5b071cf (patch)
tree3e6a817da3c9bc3dfdea25aa6497a2cbb98a9789
parentserver: purge shm buffers when terminal is destroyed (diff)
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.
-rw-r--r--terminal.c23
-rw-r--r--wayland.c7
2 files changed, 25 insertions, 5 deletions
diff --git a/terminal.c b/terminal.c
index f71d90a6..f85a9130 100644
--- a/terminal.c
+++ b/terminal.c
@@ -117,6 +117,11 @@ fdm_flash(struct fdm *fdm, int fd, int events, void *data)
return false;
}
+ if (ret == 0) {
+ /* Cancelled by other handler in *this* epoll() iteration */
+ return true;
+ }
+
LOG_DBG("flash timer expired %llu times",
(unsigned long long)expiration_count);
@@ -142,6 +147,11 @@ fdm_blink(struct fdm *fdm, int fd, int events, void *data)
return false;
}
+ if (ret == 0) {
+ /* Cancelled by other handler in *this* epoll() iteration */
+ return true;
+ }
+
LOG_DBG("blink timer expired %llu times",
(unsigned long long)expiration_count);
@@ -189,6 +199,11 @@ fdm_delayed_render(struct fdm *fdm, int fd, int events, void *data)
return false;
}
+ if (ret1 == 0 && ret2 == 0) {
+ /* Cancelled by other handler in *this* epoll() iteration */
+ return true;
+ }
+
render_refresh(term);
/* Reset timers */
@@ -304,16 +319,16 @@ term_init(const struct config *conf, struct fdm *fdm, struct wayland *wayl,
LOG_ERRNO("failed to open PTY");
goto close_fds;
}
- if ((flash_fd = timerfd_create(CLOCK_BOOTTIME, TFD_CLOEXEC)) == -1) {
+ if ((flash_fd = timerfd_create(CLOCK_BOOTTIME, TFD_CLOEXEC | TFD_NONBLOCK)) == -1) {
LOG_ERRNO("failed to create flash timer FD");
goto close_fds;
}
- if ((blink_fd = timerfd_create(CLOCK_BOOTTIME, TFD_CLOEXEC)) == -1) {
+ if ((blink_fd = timerfd_create(CLOCK_BOOTTIME, TFD_CLOEXEC | TFD_NONBLOCK)) == -1) {
LOG_ERRNO("failed to create blink timer FD");
goto close_fds;
}
- if ((delay_lower_fd = timerfd_create(CLOCK_BOOTTIME, TFD_CLOEXEC)) == -1 ||
- (delay_upper_fd = timerfd_create(CLOCK_BOOTTIME, TFD_CLOEXEC)) == -1)
+ if ((delay_lower_fd = timerfd_create(CLOCK_BOOTTIME, TFD_CLOEXEC | TFD_NONBLOCK)) == -1 ||
+ (delay_upper_fd = timerfd_create(CLOCK_BOOTTIME, TFD_CLOEXEC | TFD_NONBLOCK)) == -1)
{
LOG_ERRNO("failed to create delayed rendering timer FDs");
goto close_fds;
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;