core/tempq: Load the tempq file through an idle task

This will help reduce disk accesses during thet main startup sequence.

Implements #12: Load temporary queues through an idle task
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2016-02-25 08:14:25 -05:00
parent 279d6e0228
commit bd1e20bc56
3 changed files with 20 additions and 9 deletions

View File

@ -4,9 +4,11 @@
#include <core/collection.h>
#include <core/file.h>
#include <core/history.h>
#include <core/idle.h>
#include <core/tempq.h>
#include <glib.h>
static struct file tempq_file = FILE_INIT("deck", 1);
static struct queue_ops *tempq_ops = NULL;
static GSList *tempq_list;
static struct file tempq_file;
@ -55,14 +57,10 @@ static void __tempq_write_queue(struct queue *queue)
file_writef(&tempq_file, "\n");
}
void tempq_init(struct queue_ops *ops)
static void __tempq_init_idle(void *data)
{
unsigned int num, i;
tempq_ops = ops;
file_init(&tempq_file, "deck", 1);
if (!file_open(&tempq_file, OPEN_READ))
return;
if (file_version(&tempq_file) < 1)
@ -75,6 +73,13 @@ out:
file_close(&tempq_file);
}
void tempq_init(struct queue_ops *ops)
{
tempq_ops = ops;
idle_schedule(__tempq_init_idle, NULL);
}
void tempq_deinit()
{
while (tempq_list)

View File

@ -118,7 +118,7 @@ void gui_sidebar_init()
{
GtkPaned *pane = GTK_PANED(gui_builder_widget("o_sidebar"));
GtkTreeIter iter;
int pos, i;
int pos;
/* Set up entries in the liststore. */
sb_store = GTK_LIST_STORE(gui_builder_object("o_sidebar_store"));
@ -129,9 +129,6 @@ void gui_sidebar_init()
gtk_tree_model_iter_next(GTK_TREE_MODEL(sb_store), &iter);
__sidebar_set_queue(&iter, gui_queue(history_get_queue()));
for (i = 0; i < tempq_count(); i++)
gui_sidebar_add(gui_queue(tempq_get(i)));
/* Set sidebar width. */
pos = gui_settings_get(SIDEBAR_SETTING);
if (pos > 0)

View File

@ -20,7 +20,10 @@ static void test_init()
history_init(NULL);
test_equal((void *)tempq_next(), NULL);
tempq_init(NULL);
while (idle_run_task()) {};
test_equal((void *)tempq_next(), NULL);
tempq_move(NULL, 1);
test_equal((void *)tempq_get(0), NULL);
@ -55,6 +58,9 @@ static void test_alloc()
tempq_deinit();
test_equal(tempq_count(), 0);
tempq_init(NULL);
test_equal(tempq_count(), 0);
while (idle_run_task()) {};
test_equal(tempq_count(), 2);
q0 = tempq_get(0);
q1 = tempq_get(1);
@ -82,6 +88,7 @@ static void test_move()
tempq_deinit();
test_equal(tempq_count(), 0);
tempq_init(NULL);
while (idle_run_task()) {};
q0 = tempq_get(1);
q1 = tempq_get(0);
@ -126,6 +133,7 @@ static void test_next()
tempq_save(NULL, Q_ENABLED);
tempq_deinit();
tempq_init(NULL);
while (idle_run_task()) {};
test_equal(tempq_count(), 2);
q0 = tempq_get(0);
q1 = tempq_get(1);
@ -140,6 +148,7 @@ static void test_next()
tempq_deinit();
tempq_init(NULL);
while (idle_run_task()) {};
test_equal(tempq_count(), 1);
q1 = tempq_get(0);