From e7173f8145da293ce86cb966b0fdca6b909c7a52 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 7 Jul 2019 05:57:18 +0530 Subject: [PATCH] Linux: Fix a regression in 0.14.0 that caused the event loop to tick continuously, wasting CPU even when idle Fixes #1782 --- docs/changelog.rst | 3 +++ glfw/backend_utils.c | 1 + kitty/child-monitor.c | 13 ++++++++----- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 31a098624..4f235cf37 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -43,6 +43,9 @@ To update |kitty|, :doc:`follow the instructions `. - macOS: Fix a rare deadlock causing kitty to hang (:iss:`1779`) +- Linux: Fix a regression in 0.14.0 that caused the event loop to tick + continuously, wasting CPU even when idle (:iss:`1782`) + 0.14.2 [2019-06-09] --------------------- diff --git a/glfw/backend_utils.c b/glfw/backend_utils.c index 17c2e0c97..0d98d8e55 100644 --- a/glfw/backend_utils.c +++ b/glfw/backend_utils.c @@ -278,6 +278,7 @@ int pollForEvents(EventLoopData *eld, double timeout) { int read_ok = 0; timeout = prepareForPoll(eld, timeout); + EVDBG("pollForEvents final timeout: %.3f", timeout); int result; double end_time = monotonic() + timeout; diff --git a/kitty/child-monitor.c b/kitty/child-monitor.c index db86a5922..cb9c2a09e 100644 --- a/kitty/child-monitor.c +++ b/kitty/child-monitor.c @@ -471,8 +471,6 @@ pyset_iutf8(ChildMonitor *self, PyObject *args) { #undef INCREF_CHILD #undef DECREF_CHILD -static double last_render_at = -DBL_MAX; - extern void cocoa_update_title(PyObject*); static inline void @@ -631,6 +629,7 @@ no_render_frame_received_recently(OSWindow *w, double now, double max_wait) { static inline void render(double now) { + static double last_render_at = -DBL_MAX; double time_since_last_render = now - last_render_at; if (time_since_last_render < OPT(repaint_delay)) { set_maximum_wait(OPT(repaint_delay) - time_since_last_render); @@ -884,9 +883,13 @@ set_cocoa_pending_action(CocoaPendingAction action, const char *wd) { static void process_global_state(void *data); static void -do_state_check(id_type timer_id UNUSED, void *data) { - ChildMonitor *self = data; - process_global_state(self); +do_state_check(id_type timer_id UNUSED, void *data UNUSED) { +#ifdef __APPLE__ + process_global_state(data); +#endif + // We don't actually do anything here as process_global_state + // will be called when the loop ticks on Linux + } static id_type state_check_timer = 0;