From 3a294df4dac165ac398773569a987557d4357808 Mon Sep 17 00:00:00 2001 From: rudolf-blue Date: Thu, 8 Oct 2026 12:00:20 -0400 Subject: [PATCH] Round up poll timeout in the I/O loop Truncating to ms made the loop spin with a zero timeout until the deadline. --- kitty/child-monitor.c | 4 +++- kitty/monotonic.h | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/kitty/child-monitor.c b/kitty/child-monitor.c index d2ec83a14..7af625e28 100644 --- a/kitty/child-monitor.c +++ b/kitty/child-monitor.c @@ -1854,7 +1854,7 @@ io_loop(void *data) { if (has_pending_wakeups) { now = monotonic(); monotonic_t time_delta = OPT(input_delay) - (now - last_main_loop_wakeup_at); - if (time_delta >= 0) ret = poll(children_fds, self->count + EXTRA_FDS, monotonic_t_to_ms(time_delta)); + if (time_delta >= 0) ret = poll(children_fds, self->count + EXTRA_FDS, monotonic_t_to_ms_ceil(time_delta)); else ret = 0; } else { ret = poll(children_fds, self->count + EXTRA_FDS, -1); @@ -2032,7 +2032,9 @@ accept_peer(int listen_fd, bool shutting_down, bool is_remote_control_peer, bool return true; } } + talk_mutex(lock); add_peer(peer, is_remote_control_peer); + talk_mutex(unlock); return true; } diff --git a/kitty/monotonic.h b/kitty/monotonic.h index 0b8b26e8e..00ce9518b 100644 --- a/kitty/monotonic.h +++ b/kitty/monotonic.h @@ -43,6 +43,11 @@ monotonic_t_to_ms(monotonic_t time) { return (int)(time / MONOTONIC_T_1e6); } +static inline int +monotonic_t_to_ms_ceil(monotonic_t time) { + return (int)((time + MONOTONIC_T_1e6 - 1) / MONOTONIC_T_1e6); +} + static inline int monotonic_t_to_us(monotonic_t time) { return (int)(time / MONOTONIC_T_1e3);