From f46ef37630c6a7ca69119f849523a68069573cbb Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Sat, 24 Sep 2016 09:57:51 -0400 Subject: [PATCH] core/idle: Change idle_init() to take an idle_sync_t Rather than offering two init functions for testing. This lets the UI select if they want async idle tasks (like Album Art fetching). Implements #90: Give idle_init an async flag Signed-off-by: Anna Schumaker --- core/core.c | 7 +------ core/idle.c | 11 +++-------- gui/ocarina.c | 7 ++++--- include/core/core.h | 5 ++--- include/core/idle.h | 5 +---- tests/core/idle.c | 2 +- tests/core/playlist.c | 2 +- tests/core/playlists/artist.c | 2 +- tests/core/playlists/library.c | 2 +- tests/core/playlists/system.c | 2 +- tests/core/playlists/user.c | 2 +- tests/core/tags/album.c | 6 +++--- tests/core/tags/track.c | 2 +- tests/gui/artwork.c | 6 ++++-- 14 files changed, 25 insertions(+), 36 deletions(-) diff --git a/core/core.c b/core/core.c index 871bb173..60867b2c 100644 --- a/core/core.c +++ b/core/core.c @@ -20,12 +20,7 @@ static bool core_defragment(void *data) void core_init(int *argc, char ***argv, struct core_init_data *init) { -#ifdef CONFIG_TESTING - if (init->idle_async == false) - idle_init_sync(); - else -#endif /* CONFIG_TESTING */ - idle_init(); + idle_init(init->idle_sync); settings_init(); tags_init(); playlist_init(init->playlist_cb); diff --git a/core/idle.c b/core/idle.c index 0db4ad1e..6369f146 100644 --- a/core/idle.c +++ b/core/idle.c @@ -38,17 +38,12 @@ void __idle_thread(gpointer task, gpointer data) } -void idle_init() +void idle_init(enum idle_sync_t idle_sync) { - idle_pool = g_thread_pool_new(__idle_thread, NULL, 1, true, NULL); + if (idle_sync == IDLE_ASYNC) + idle_pool = g_thread_pool_new(__idle_thread, NULL, 1, true, NULL); } -#ifdef CONFIG_TESTING -void idle_init_sync() -{ -} -#endif /* CONFIG_TESTING */ - void idle_deinit() { struct idle_task *task; diff --git a/gui/ocarina.c b/gui/ocarina.c index 15f2ce80..aeb170e4 100644 --- a/gui/ocarina.c +++ b/gui/ocarina.c @@ -31,9 +31,10 @@ const static gchar *OCARINA_APP = "org.gtk.ocarina"; const static gchar *OCARINA_APP = "org.gtk.ocarina-debug"; #endif -struct core_init_data init_data = { - .playlist_cb = &playlist_cb, - .audio_ops = &audio_ops, +static struct core_init_data init_data = { + .playlist_cb = &playlist_cb, + .audio_ops = &audio_ops, + .idle_sync = IDLE_ASYNC, }; static int startup_argc; diff --git a/include/core/core.h b/include/core/core.h index 85b315d3..317967fd 100644 --- a/include/core/core.h +++ b/include/core/core.h @@ -3,14 +3,13 @@ */ #ifndef OCARINA_CORE_CORE_H #define OCARINA_CORE_CORE_H +#include #include struct core_init_data { struct playlist_callbacks *playlist_cb; struct audio_ops *audio_ops; -#ifdef CONFIG_TESTING - bool idle_async; -#endif /* CONFIG_TESTING */ + enum idle_sync_t idle_sync; }; diff --git a/include/core/idle.h b/include/core/idle.h index 4d182d81..b089621b 100644 --- a/include/core/idle.h +++ b/include/core/idle.h @@ -24,10 +24,7 @@ enum idle_sync_t { /* Called to initialize the idle queue. */ -void idle_init(); -#ifdef CONFIG_TESTING -void idle_init_sync(); -#endif /* CONFIG_TESTING */ +void idle_init(enum idle_sync_t); /* Called to deinitialize the idle queue. */ void idle_deinit(); diff --git a/tests/core/idle.c b/tests/core/idle.c index 916336e7..0406f980 100644 --- a/tests/core/idle.c +++ b/tests/core/idle.c @@ -19,7 +19,7 @@ static void test_idle(gconstpointer arg) unsigned int n = GPOINTER_TO_UINT(arg); cur = -1; - idle_init(); + idle_init(IDLE_ASYNC); g_assert_cmpfloat(idle_progress(), ==, 1.0); g_assert_false(idle_run_task()); diff --git a/tests/core/playlist.c b/tests/core/playlist.c index 2243a05d..9aa8f3d4 100644 --- a/tests/core/playlist.c +++ b/tests/core/playlist.c @@ -377,7 +377,7 @@ int main(int argc, char **argv) struct library *library; int ret; - idle_init_sync(); + idle_init(IDLE_SYNC); settings_init(); tags_init(); playlist_init(&test_cb); diff --git a/tests/core/playlists/artist.c b/tests/core/playlists/artist.c index b049f3f1..845ff531 100644 --- a/tests/core/playlists/artist.c +++ b/tests/core/playlists/artist.c @@ -62,7 +62,7 @@ int main(int argc, char **argv) struct library *library; int ret; - idle_init_sync(); + idle_init(IDLE_SYNC); settings_init(); tags_init(); playlist_init(NULL); diff --git a/tests/core/playlists/library.c b/tests/core/playlists/library.c index c3842bcc..00134f64 100644 --- a/tests/core/playlists/library.c +++ b/tests/core/playlists/library.c @@ -112,7 +112,7 @@ int main(int argc, char **argv) { int ret; - idle_init_sync(); + idle_init(IDLE_SYNC); settings_init(); tags_init(); playlist_init(NULL); diff --git a/tests/core/playlists/system.c b/tests/core/playlists/system.c index f5293dce..174701c8 100644 --- a/tests/core/playlists/system.c +++ b/tests/core/playlists/system.c @@ -373,7 +373,7 @@ int main(int argc, char **argv) { int ret; - idle_init_sync(); + idle_init(IDLE_SYNC); settings_init(); tags_init(); playlist_init(NULL); diff --git a/tests/core/playlists/user.c b/tests/core/playlists/user.c index ae197bca..72736301 100644 --- a/tests/core/playlists/user.c +++ b/tests/core/playlists/user.c @@ -78,7 +78,7 @@ int main(int argc, char **argv) { int ret; - idle_init_sync(); + idle_init(IDLE_SYNC); settings_init(); tags_init(); playlist_init(NULL); diff --git a/tests/core/tags/album.c b/tests/core/tags/album.c index 53c08814..36aa66e8 100644 --- a/tests/core/tags/album.c +++ b/tests/core/tags/album.c @@ -48,7 +48,7 @@ static void test_album() struct genre *genre; struct file f; - idle_init(); + idle_init(IDLE_SYNC); koji = artist_find("Koji Kondo"); genre = genre_find("Video Game Music"); @@ -134,7 +134,7 @@ static void test_album_artwork() const gchar *cache; idle_deinit(); - idle_init(); + idle_init(IDLE_ASYNC); cache = g_get_user_cache_dir(); o_path = g_build_filename(cache, "ocarina-test", "core", "tags", "album", "1998", "Ocarina of Time.jpg", NULL); @@ -182,7 +182,7 @@ int main(int argc, char **argv) { int ret; - idle_init_sync(); + idle_init(IDLE_SYNC); artist_db_init(); genre_db_init(); album_db_init(); diff --git a/tests/core/tags/track.c b/tests/core/tags/track.c index 9ec5f51d..eae4134f 100644 --- a/tests/core/tags/track.c +++ b/tests/core/tags/track.c @@ -302,7 +302,7 @@ int main(int argc, char **argv) int ret; setlocale(LC_TIME, "C"); - idle_init_sync(); + idle_init(IDLE_SYNC); tags_init(); while (idle_run_task()) {} diff --git a/tests/gui/artwork.c b/tests/gui/artwork.c index ce5f1231..a95b46c0 100644 --- a/tests/gui/artwork.c +++ b/tests/gui/artwork.c @@ -23,9 +23,11 @@ static struct audio_ops test_audio_ops = { }; struct core_init_data init_data = { - .audio_ops = &test_audio_ops, + .audio_ops = &test_audio_ops, #ifdef CONFIG_ALBUM_ART_TEST - .idle_async = true, + .idle_sync = IDLE_ASYNC, +#else /* CONFIG_ALBUM_ART_TEST */ + .idle_sync = IDLE_SYNC, #endif /* CONFIG_ALBUM_ART_TEST */ };