From 376742c50f2909ae763d909e7004feb9366156ef Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Thu, 27 Aug 2009 01:26:55 -0400 Subject: [PATCH] [event-loop] Add ply_event_loop_get_default () The event loop is used all through out the code for many different things. In order to use it in all those various bits of code, it's getting passed around a lot. This adds a lot of complexity to the code. The event loop should probably be a standard resource that all parts of the code have free access to in the same vein as the logging apis. This commit adds a new function ply_event_loop_get_default () and makes main use it and pass it along. Subsequent commits may clean up all the places that take an event loop to just use this instead. --- src/libply/ply-event-loop.c | 11 +++++++++++ src/libply/ply-event-loop.h | 1 + src/main.c | 5 +---- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/libply/ply-event-loop.c b/src/libply/ply-event-loop.c index 2c03a528..33bd52c7 100644 --- a/src/libply/ply-event-loop.c +++ b/src/libply/ply-event-loop.c @@ -489,6 +489,17 @@ ply_event_loop_new (void) return loop; } +ply_event_loop_t * +ply_event_loop_get_default (void) +{ + static ply_event_loop_t *loop = NULL; + + if (loop == NULL) + loop = ply_event_loop_new (); + + return loop; +} + static void ply_event_loop_free_exit_closures (ply_event_loop_t *loop) { diff --git a/src/libply/ply-event-loop.h b/src/libply/ply-event-loop.h index 98b9cd17..ae29d285 100644 --- a/src/libply/ply-event-loop.h +++ b/src/libply/ply-event-loop.h @@ -48,6 +48,7 @@ typedef void (* ply_event_loop_timeout_handler_t) (void *user_data, #ifndef PLY_HIDE_FUNCTION_DECLARATIONS ply_event_loop_t *ply_event_loop_new (void); void ply_event_loop_free (ply_event_loop_t *loop); +ply_event_loop_t *ply_event_loop_get_default (void); ply_fd_watch_t *ply_event_loop_watch_fd (ply_event_loop_t *loop, int fd, ply_event_loop_fd_status_t status, diff --git a/src/main.c b/src/main.c index a77c45b6..3b40afab 100644 --- a/src/main.c +++ b/src/main.c @@ -1359,7 +1359,7 @@ main (int argc, state.command_parser = ply_command_parser_new ("plymouthd", "Boot splash control server"); - state.loop = ply_event_loop_new (); + state.loop = ply_event_loop_get_default (); ply_command_parser_add_options (state.command_parser, "help", "This help message", PLY_COMMAND_OPTION_TYPE_FLAG, @@ -1526,9 +1526,6 @@ main (int argc, ply_buffer_free (state.boot_buffer); ply_progress_free (state.progress); - ply_trace ("freeing event loop"); - ply_event_loop_free (state.loop); - ply_trace ("exiting with code %d", exit_code); if (debug_buffer != NULL) -- 2.47.3