diff options
author | Max Kellermann <max@duempel.org> | 2011-08-25 18:27:10 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2011-08-25 18:43:05 +0200 |
commit | 0f1e4f032611ffc92ecb5abed53b000da9aa09d7 (patch) | |
tree | b4bb90e800195567dba5c4909fd03943e0ad9123 | |
parent | 89355edb8a28c4a72d841a79d5bf261a8b244569 (diff) | |
download | mpd-0f1e4f032611ffc92ecb5abed53b000da9aa09d7.tar.gz mpd-0f1e4f032611ffc92ecb5abed53b000da9aa09d7.tar.xz mpd-0f1e4f032611ffc92ecb5abed53b000da9aa09d7.zip |
io_thread: move global variables into a struct
-rw-r--r-- | src/io_thread.c | 52 |
1 files changed, 27 insertions, 25 deletions
diff --git a/src/io_thread.c b/src/io_thread.c index 69d6fb71a..0942f9a40 100644 --- a/src/io_thread.c +++ b/src/io_thread.c @@ -21,40 +21,42 @@ #include <assert.h> -static GMainContext *io_context; -static GMainLoop *io_loop; -static GThread *io_thread; +static struct { + GMainContext *context; + GMainLoop *loop; + GThread *thread; +} io; static gpointer io_thread_func(G_GNUC_UNUSED gpointer arg) { - assert(io_context != NULL); - assert(io_loop != NULL); + assert(io.context != NULL); + assert(io.loop != NULL); - g_main_loop_run(io_loop); + g_main_loop_run(io.loop); return NULL; } void io_thread_init(void) { - assert(io_context == NULL); - assert(io_loop == NULL); - assert(io_thread == NULL); + assert(io.context == NULL); + assert(io.loop == NULL); + assert(io.thread == NULL); - io_context = g_main_context_new(); - io_loop = g_main_loop_new(io_context, false); + io.context = g_main_context_new(); + io.loop = g_main_loop_new(io.context, false); } bool io_thread_start(GError **error_r) { - assert(io_context != NULL); - assert(io_loop != NULL); - assert(io_thread == NULL); + assert(io.context != NULL); + assert(io.loop != NULL); + assert(io.thread == NULL); - io_thread = g_thread_create(io_thread_func, NULL, true, error_r); - if (io_thread == NULL) + io.thread = g_thread_create(io_thread_func, NULL, true, error_r); + if (io.thread == NULL) return false; return true; @@ -63,23 +65,23 @@ io_thread_start(GError **error_r) void io_thread_deinit(void) { - if (io_thread != NULL) { - assert(io_loop != NULL); + if (io.thread != NULL) { + assert(io.loop != NULL); - g_main_loop_quit(io_loop); - g_thread_join(io_thread); + g_main_loop_quit(io.loop); + g_thread_join(io.thread); } - if (io_loop != NULL) - g_main_loop_unref(io_loop); + if (io.loop != NULL) + g_main_loop_unref(io.loop); - if (io_context != NULL) - g_main_context_unref(io_context); + if (io.context != NULL) + g_main_context_unref(io.context); } GMainContext * io_thread_context(void) { - return io_context; + return io.context; } |