From 9a7668a50661ed7526620536a1b586a2f79b7ab7 Mon Sep 17 00:00:00 2001 From: StefanBruens Date: Wed, 13 Dec 2023 05:48:51 +0100 Subject: [PATCH] jackdbus: Stop recurrent wakeups when no save is pending Most processing happens as a result of an incoming DBus event. The only case when a timed processing is needed is due to an pending save. Instead of implementing a full event loop just run the timed loop while a save is pending, and use an infinite timeout otherwise. Fix for https://github.com/jackaudio/jack2/issues/962 Thanks you @StefanBruens (cherry picked from commit fd1ac1422460c02cba17ea3053a4e6517290750c) --- dbus/controller.c | 7 ++++--- dbus/controller.h | 4 +++- dbus/jackdbus.c | 6 ++++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/dbus/controller.c b/dbus/controller.c index 1430994f..78b87555 100644 --- a/dbus/controller.c +++ b/dbus/controller.c @@ -720,7 +720,7 @@ jack_controller_destroy( free(controller_ptr); } -void +bool jack_controller_run( void * context) { @@ -728,7 +728,7 @@ jack_controller_run( if (controller_ptr->pending_save == 0) { - return; + return false; } if (sysinfo(&si) != 0) @@ -737,11 +737,12 @@ jack_controller_run( } else if (si.uptime < controller_ptr->pending_save + 2) /* delay save by two seconds */ { - return; + return true; } controller_ptr->pending_save = 0; jack_controller_settings_save_auto(controller_ptr); + return false; } #undef controller_ptr diff --git a/dbus/controller.h b/dbus/controller.h index 1db79ecd..0294ca2e 100644 --- a/dbus/controller.h +++ b/dbus/controller.h @@ -20,11 +20,13 @@ #ifndef CONTROLLER_H__2CC80B1E_8D5D_45E3_A9D8_9086DDF68BB5__INCLUDED #define CONTROLLER_H__2CC80B1E_8D5D_45E3_A9D8_9086DDF68BB5__INCLUDED +#include + void * jack_controller_create( DBusConnection *connection); -void +bool jack_controller_run( void *controller_ptr); diff --git a/dbus/jackdbus.c b/dbus/jackdbus.c index b6e2698d..2e331f2b 100644 --- a/dbus/jackdbus.c +++ b/dbus/jackdbus.c @@ -857,6 +857,7 @@ main (int argc, char **argv) void *controller_ptr; struct stat st; char timestamp_str[26]; + bool save_pending; st.st_mtime = 0; stat(argv[0], &st); @@ -954,9 +955,10 @@ main (int argc, char **argv) jack_info("Listening for D-Bus messages"); g_exit_command = FALSE; - while (!g_exit_command && dbus_connection_read_write_dispatch (g_connection, 200)) + save_pending = false; + while (!g_exit_command && dbus_connection_read_write_dispatch (g_connection, (save_pending ? 200 : -1))) { - jack_controller_run(controller_ptr); + save_pending = jack_controller_run(controller_ptr); } jack_controller_destroy(controller_ptr);