From 67bd22c154ccc6d32ebc0d9adcb16b4ebb33e452 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Eric=20Janouch?= Date: Sun, 7 Nov 2021 14:45:56 +0100 Subject: poller-pa.c: abandon the idea of quitting the loop There are no users of this API in practice, and it prevents making the libpulse dependency optional. --- paswitch.c | 11 +++++++---- poller-pa.c | 23 +++++------------------ wmstatus.c | 3 ++- 3 files changed, 14 insertions(+), 23 deletions(-) diff --git a/paswitch.c b/paswitch.c index b43fc00..ba7ffc8 100644 --- a/paswitch.c +++ b/paswitch.c @@ -143,6 +143,7 @@ struct app_context struct poller_timer tty_timer; ///< Terminal input timeout struct str tty_input_buffer; ///< Buffered terminal input + bool quitting; ///< Quitting requested pa_mainloop_api *api; ///< PulseAudio event loop proxy pa_context *context; ///< PulseAudio connection context @@ -683,7 +684,7 @@ on_action (struct app_context *ctx, enum action action) break; case ACTION_QUIT: - poller_pa_quit (ctx->api, 0); + ctx->quitting = true; case ACTION_NONE: break; } @@ -910,7 +911,7 @@ on_signal_pipe_readable (const struct pollfd *pfd, struct app_context *ctx) (void) read (pfd->fd, &id, 1); if (id == SIGINT || id == SIGTERM || id == SIGHUP) - poller_pa_quit (ctx->api, 0); + ctx->quitting = true; else if (id == SIGWINCH) poller_idle_set (&ctx->redraw_event); else @@ -1068,7 +1069,9 @@ main (int argc, char *argv[]) poller_timer_init_and_set (&ctx.make_context, &ctx.poller, on_make_context, &ctx); - int status = poller_pa_run (ctx.api); + while (!ctx.quitting) + poller_run (&ctx.poller); + app_context_free (&ctx); - return status; + return 0; } diff --git a/poller-pa.c b/poller-pa.c index 24d70a4..3f59c1b 100644 --- a/poller-pa.c +++ b/poller-pa.c @@ -59,9 +59,6 @@ struct pa_defer_event struct poller_pa { struct poller *poller; ///< The underlying event loop - int result; ///< Result on quit - bool running; ///< Not quitting - pa_io_event *io_list; ///< I/O events pa_time_event *time_list; ///< Timer events pa_defer_event *defer_list; ///< Deferred events @@ -293,9 +290,11 @@ poller_pa_defer_set_destroy (pa_defer_event *self, static void poller_pa_quit (pa_mainloop_api *api, int retval) { - struct poller_pa *data = api->userdata; - data->result = retval; - data->running = false; + (void) api; + (void) retval; + + // This is not called from within libpulse + hard_assert (!"quitting the libpulse event loop is unimplemented"); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -347,15 +346,3 @@ poller_pa_destroy (struct pa_mainloop_api *api) free (data); free (api); } - -/// Since our poller API doesn't care much about continuous operation, -/// we need to provide that in the PulseAudio abstraction itself -static int -poller_pa_run (struct pa_mainloop_api *api) -{ - struct poller_pa *data = api->userdata; - data->running = true; - while (data->running) - poller_run (data->poller); - return data->result; -} diff --git a/wmstatus.c b/wmstatus.c index e8d26e1..de7d63d 100644 --- a/wmstatus.c +++ b/wmstatus.c @@ -2745,7 +2745,8 @@ main (int argc, char *argv[]) if (ctx.backend->start) ctx.backend->start (ctx.backend); - poller_pa_run (ctx.api); + while (true) + poller_run (&ctx.poller); if (ctx.backend->stop) ctx.backend->stop (ctx.backend); -- cgit v1.2.3