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 <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2016-09-24 09:57:51 -04:00
parent 76ebfaa6d4
commit f46ef37630
14 changed files with 25 additions and 36 deletions

View File

@ -20,12 +20,7 @@ static bool core_defragment(void *data)
void core_init(int *argc, char ***argv, struct core_init_data *init) void core_init(int *argc, char ***argv, struct core_init_data *init)
{ {
#ifdef CONFIG_TESTING idle_init(init->idle_sync);
if (init->idle_async == false)
idle_init_sync();
else
#endif /* CONFIG_TESTING */
idle_init();
settings_init(); settings_init();
tags_init(); tags_init();
playlist_init(init->playlist_cb); playlist_init(init->playlist_cb);

View File

@ -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() void idle_deinit()
{ {
struct idle_task *task; struct idle_task *task;

View File

@ -31,9 +31,10 @@ const static gchar *OCARINA_APP = "org.gtk.ocarina";
const static gchar *OCARINA_APP = "org.gtk.ocarina-debug"; const static gchar *OCARINA_APP = "org.gtk.ocarina-debug";
#endif #endif
struct core_init_data init_data = { static struct core_init_data init_data = {
.playlist_cb = &playlist_cb, .playlist_cb = &playlist_cb,
.audio_ops = &audio_ops, .audio_ops = &audio_ops,
.idle_sync = IDLE_ASYNC,
}; };
static int startup_argc; static int startup_argc;

View File

@ -3,14 +3,13 @@
*/ */
#ifndef OCARINA_CORE_CORE_H #ifndef OCARINA_CORE_CORE_H
#define OCARINA_CORE_CORE_H #define OCARINA_CORE_CORE_H
#include <core/idle.h>
#include <stdbool.h> #include <stdbool.h>
struct core_init_data { struct core_init_data {
struct playlist_callbacks *playlist_cb; struct playlist_callbacks *playlist_cb;
struct audio_ops *audio_ops; struct audio_ops *audio_ops;
#ifdef CONFIG_TESTING enum idle_sync_t idle_sync;
bool idle_async;
#endif /* CONFIG_TESTING */
}; };

View File

@ -24,10 +24,7 @@ enum idle_sync_t {
/* Called to initialize the idle queue. */ /* Called to initialize the idle queue. */
void idle_init(); void idle_init(enum idle_sync_t);
#ifdef CONFIG_TESTING
void idle_init_sync();
#endif /* CONFIG_TESTING */
/* Called to deinitialize the idle queue. */ /* Called to deinitialize the idle queue. */
void idle_deinit(); void idle_deinit();

View File

@ -19,7 +19,7 @@ static void test_idle(gconstpointer arg)
unsigned int n = GPOINTER_TO_UINT(arg); unsigned int n = GPOINTER_TO_UINT(arg);
cur = -1; cur = -1;
idle_init(); idle_init(IDLE_ASYNC);
g_assert_cmpfloat(idle_progress(), ==, 1.0); g_assert_cmpfloat(idle_progress(), ==, 1.0);
g_assert_false(idle_run_task()); g_assert_false(idle_run_task());

View File

@ -377,7 +377,7 @@ int main(int argc, char **argv)
struct library *library; struct library *library;
int ret; int ret;
idle_init_sync(); idle_init(IDLE_SYNC);
settings_init(); settings_init();
tags_init(); tags_init();
playlist_init(&test_cb); playlist_init(&test_cb);

View File

@ -62,7 +62,7 @@ int main(int argc, char **argv)
struct library *library; struct library *library;
int ret; int ret;
idle_init_sync(); idle_init(IDLE_SYNC);
settings_init(); settings_init();
tags_init(); tags_init();
playlist_init(NULL); playlist_init(NULL);

View File

@ -112,7 +112,7 @@ int main(int argc, char **argv)
{ {
int ret; int ret;
idle_init_sync(); idle_init(IDLE_SYNC);
settings_init(); settings_init();
tags_init(); tags_init();
playlist_init(NULL); playlist_init(NULL);

View File

@ -373,7 +373,7 @@ int main(int argc, char **argv)
{ {
int ret; int ret;
idle_init_sync(); idle_init(IDLE_SYNC);
settings_init(); settings_init();
tags_init(); tags_init();
playlist_init(NULL); playlist_init(NULL);

View File

@ -78,7 +78,7 @@ int main(int argc, char **argv)
{ {
int ret; int ret;
idle_init_sync(); idle_init(IDLE_SYNC);
settings_init(); settings_init();
tags_init(); tags_init();
playlist_init(NULL); playlist_init(NULL);

View File

@ -48,7 +48,7 @@ static void test_album()
struct genre *genre; struct genre *genre;
struct file f; struct file f;
idle_init(); idle_init(IDLE_SYNC);
koji = artist_find("Koji Kondo"); koji = artist_find("Koji Kondo");
genre = genre_find("Video Game Music"); genre = genre_find("Video Game Music");
@ -134,7 +134,7 @@ static void test_album_artwork()
const gchar *cache; const gchar *cache;
idle_deinit(); idle_deinit();
idle_init(); idle_init(IDLE_ASYNC);
cache = g_get_user_cache_dir(); cache = g_get_user_cache_dir();
o_path = g_build_filename(cache, "ocarina-test", "core", "tags", "album", "1998", "Ocarina of Time.jpg", NULL); 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; int ret;
idle_init_sync(); idle_init(IDLE_SYNC);
artist_db_init(); artist_db_init();
genre_db_init(); genre_db_init();
album_db_init(); album_db_init();

View File

@ -302,7 +302,7 @@ int main(int argc, char **argv)
int ret; int ret;
setlocale(LC_TIME, "C"); setlocale(LC_TIME, "C");
idle_init_sync(); idle_init(IDLE_SYNC);
tags_init(); tags_init();
while (idle_run_task()) {} while (idle_run_task()) {}

View File

@ -23,9 +23,11 @@ static struct audio_ops test_audio_ops = {
}; };
struct core_init_data init_data = { struct core_init_data init_data = {
.audio_ops = &test_audio_ops, .audio_ops = &test_audio_ops,
#ifdef CONFIG_ALBUM_ART_TEST #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 */ #endif /* CONFIG_ALBUM_ART_TEST */
}; };