refactor: move shutdown logic out of signal handler into main loop
This commit is contained in:
committed by
Loic Coenen (aider)
parent
dd67576c45
commit
cd1adba9e3
@@ -79,15 +79,19 @@ static void looper_cleanup(jack_client_t *client) {
|
||||
}
|
||||
}
|
||||
|
||||
/* Signal handler: deactivate and cleanup before exit */
|
||||
void looper_shutdown(jack_client_t *client) {
|
||||
jack_deactivate(client);
|
||||
looper_cleanup(client);
|
||||
jack_client_close(client);
|
||||
log_close();
|
||||
}
|
||||
|
||||
volatile int looper_quit = 0;
|
||||
|
||||
/* Signal handler: set quit flag only */
|
||||
static void signal_handler(int sig) {
|
||||
(void)sig;
|
||||
if (global_client) {
|
||||
looper_cleanup(global_client);
|
||||
jack_client_close(global_client);
|
||||
}
|
||||
log_close();
|
||||
exit(0);
|
||||
looper_quit = 1;
|
||||
}
|
||||
|
||||
static void looper_write_status(void) {
|
||||
|
||||
@@ -16,4 +16,10 @@ void jack_shutdown_cb(void *arg);
|
||||
/* Main‑loop command processing (add/remove channels) */
|
||||
void looper_process_commands(jack_client_t *client);
|
||||
|
||||
/* Shutdown (must be called from the main thread after looper_quit is set) */
|
||||
void looper_shutdown(jack_client_t *client);
|
||||
|
||||
/* Flag set by signal handler – main loop should check this */
|
||||
extern volatile int looper_quit;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -49,7 +49,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
log_msg("looper running (client name '%s')", client_name);
|
||||
|
||||
while (1) {
|
||||
while (!looper_quit) {
|
||||
looper_process_commands(client);
|
||||
{
|
||||
struct timespec ts = {.tv_sec = 0, .tv_nsec = 10000000};
|
||||
@@ -57,7 +57,6 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
}
|
||||
|
||||
jack_client_close(client);
|
||||
log_close();
|
||||
looper_shutdown(client);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user