Skip to content

Commit

Permalink
jackdbus: Stop recurrent wakeups when no save is pending
Browse files Browse the repository at this point in the history
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 jackaudio/jack2#962

Thanks @StefanBruens

(cherry picked from commit fd1ac1422460c02cba17ea3053a4e6517290750c)
  • Loading branch information
StefanBruens authored and nedko committed Aug 26, 2024
1 parent 109c2ee commit aef0259
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
7 changes: 4 additions & 3 deletions dbus/controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -720,15 +720,15 @@ jack_controller_destroy(
free(controller_ptr);
}

void
bool
jack_controller_run(
void * context)
{
struct sysinfo si;

if (controller_ptr->pending_save == 0)
{
return;
return false;
}

if (sysinfo(&si) != 0)
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion dbus/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
#ifndef CONTROLLER_H__2CC80B1E_8D5D_45E3_A9D8_9086DDF68BB5__INCLUDED
#define CONTROLLER_H__2CC80B1E_8D5D_45E3_A9D8_9086DDF68BB5__INCLUDED

#include <stdbool.h>

void *
jack_controller_create(
DBusConnection *connection);

void
bool
jack_controller_run(
void *controller_ptr);

Expand Down
6 changes: 4 additions & 2 deletions dbus/jackdbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit aef0259

Please sign in to comment.