From f706ccb77cc02769f268438f8d3a982b56d00ad1 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Thu, 25 Feb 2016 08:33:03 -0500 Subject: [PATCH] core/collection: Initialize the collection through an idle task Scan over all tracks in the database first, and then schedule a collection update. Implements #13: Load collection queue through an idle task Signed-off-by: Anna Schumaker --- core/collection.c | 20 ++++++++++++-------- tests/core/collection.c | 8 ++++++++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/core/collection.c b/core/collection.c index 9d6d7021..b5cf2f2f 100644 --- a/core/collection.c +++ b/core/collection.c @@ -112,19 +112,12 @@ static void __validate_library(void *data) } } - - -/* - * External API begins here - */ -void collection_init(struct queue_ops *ops) +void __collection_init_idle(void *data) { struct db_entry *track, *next; unsigned int i, n = 0; int field, ascending; - queue_init(&c_queue, Q_ENABLED | Q_REPEAT | Q_ADD_FRONT, ops); - db_for_each(track, next, track_db_get()) { if (TRACK(track)->tr_library->li_enabled && !playlist_has(PL_HIDDEN, TRACK(track))) @@ -155,6 +148,17 @@ void collection_init(struct queue_ops *ops) collection_update_all(); } + + +/* + * External API begins here + */ +void collection_init(struct queue_ops *ops) +{ + queue_init(&c_queue, Q_ENABLED | Q_REPEAT | Q_ADD_FRONT, ops); + idle_schedule(__collection_init_idle, NULL); +} + void collection_deinit() { queue_deinit(&c_queue); diff --git a/tests/core/collection.c b/tests/core/collection.c index 1d4a5fec..17c93c4f 100644 --- a/tests/core/collection.c +++ b/tests/core/collection.c @@ -22,6 +22,13 @@ static void test_init() test_not_equal((void *)q, NULL); test_equal(queue_has_flag(q, Q_ENABLED), (bool)true); test_equal(queue_has_flag(q, Q_REPEAT), (bool)true); + test_equal(queue_has_flag(q, Q_SAVE_SORT), (bool)false); + test_equal(queue_has_flag(q, Q_SAVE_FLAGS), (bool)false); + test_equal(queue_has_flag(q, Q_ADD_FRONT), (bool)true); + + while (idle_run_task()) {}; + test_equal(queue_has_flag(q, Q_ENABLED), (bool)true); + test_equal(queue_has_flag(q, Q_REPEAT), (bool)true); test_equal(queue_has_flag(q, Q_SAVE_SORT), (bool)true); test_equal(queue_has_flag(q, Q_SAVE_FLAGS), (bool)true); test_equal(queue_has_flag(q, Q_ADD_FRONT), (bool)false); @@ -211,6 +218,7 @@ static void test_save_load() } collection_init(NULL); + while (idle_run_task()) {}; test_equal(queue_size(q), track_db_get()->db_size / 2); test_equal(g_slist_length(q->q_sort), 2);