core/idle: Add idle_sync_t enum

I intend to use this to select between sync and async idle tasks.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2016-04-30 09:16:02 -04:00
parent a6bfbbb1c6
commit 6a44f9e1a1
9 changed files with 18 additions and 13 deletions

View File

@ -117,7 +117,7 @@ void audio_init(int *argc, char ***argv, struct audio_ops *ops)
audio_bus = gst_bus_add_watch(bus, __audio_message, NULL);
gst_object_unref(bus);
idle_schedule(__audio_init_idle, NULL);
idle_schedule(IDLE_SYNC, __audio_init_idle, NULL);
}
void audio_deinit()

View File

@ -42,7 +42,7 @@ static void __scan_dir_later(struct library *library, const gchar *dir)
data->sd_path = g_strdup(dir);
/* data is freed by __scan_dir() */
idle_schedule(__scan_dir, data);
idle_schedule(IDLE_SYNC, __scan_dir, data);
}
static void __scan_path(struct scan_data *scan, const gchar *name)
@ -156,7 +156,7 @@ void __collection_init_idle(void *data)
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);
idle_schedule(IDLE_SYNC, __collection_init_idle, NULL);
}
void collection_deinit()
@ -211,7 +211,7 @@ void collection_update(struct library *library)
if (!library)
return;
idle_schedule(__validate_library, library);
idle_schedule(IDLE_SYNC, __validate_library, library);
__scan_dir_later(library, library->li_path);
}

View File

@ -131,7 +131,7 @@ void db_load(struct database *db)
void db_load_idle(struct database *db)
{
idle_schedule((void (*)(void *))db_load, db);
idle_schedule(IDLE_SYNC, IDLE_FUNC(db_load), db);
}
struct db_entry *db_insert(struct database *db, const gchar *key)

View File

@ -2,7 +2,6 @@
* Copyright 2013 (c) Anna Schumaker.
*/
#include <core/idle.h>
#include <glib.h>
@ -16,7 +15,7 @@ static float queued = 0.0;
static float serviced = 0.0;
void idle_schedule(void (*func)(void *), void *data)
void idle_schedule(enum idle_sync_t sync, void (*func)(void *), void *data)
{
struct idle_task *task = g_malloc(sizeof(struct idle_task));
task->idle_func = func;

View File

@ -74,7 +74,7 @@ static void __tempq_init_idle(void *data)
void tempq_init(struct queue_ops *ops)
{
tempq_ops = ops;
idle_schedule(__tempq_init_idle, NULL);
idle_schedule(IDLE_SYNC, __tempq_init_idle, NULL);
}
void tempq_deinit()

View File

@ -231,7 +231,7 @@ void gui_collection_init()
gtk_tree_view_get_selection(treeview),
gui_sidebar_on_select, NULL, NULL);
idle_schedule(__gui_collection_init_idle, NULL);
idle_schedule(IDLE_SYNC, __gui_collection_init_idle, NULL);
gui_sidebar_set_size(gui_queue(collection_get_queue()));
gui_idle_enable();
}

View File

@ -15,8 +15,14 @@
#define OCARINA_CORE_IDLE_H
#include <stdbool.h>
enum idle_sync_t {
IDLE_SYNC, /* Run task in the main thread. */
};
#define IDLE_FUNC(x) ((void (*)(void *))x)
/* Called to schedule a function to run later. */
void idle_schedule(void (*)(void *), void *);
void idle_schedule(enum idle_sync_t, void (*)(void *), void *);
/*
* Called to run the next task on the idle queue.

View File

@ -25,7 +25,7 @@ static void test_idle_queue(unsigned int n)
test_equal(idle_run_task(), (bool)false);
for (unsigned int i = 0; i < n; i++)
idle_schedule(inc_cur, GINT_TO_POINTER(i));
idle_schedule(IDLE_SYNC, inc_cur, GINT_TO_POINTER(i));
test_equal(idle_progress(), (float)0.0);
for (unsigned int i = 0; i < (n - 1); i++) {
@ -38,7 +38,7 @@ static void test_idle_queue(unsigned int n)
test_equal(idle_progress(), (float)1.0);
for (unsigned int i = 0; i < n; i++)
idle_schedule(inc_cur, GINT_TO_POINTER(i));
idle_schedule(IDLE_SYNC, inc_cur, GINT_TO_POINTER(i));
test_equal(idle_progress(), (float)0.0);
idle_cancel();

View File

@ -52,7 +52,7 @@ static void test_idle()
test_equal(gtk_widget_is_visible(GTK_WIDGET(progress)), false);
for (i = 0; i < N; i++)
idle_schedule(inc_cur, GINT_TO_POINTER(i));
idle_schedule(IDLE_SYNC, inc_cur, GINT_TO_POINTER(i));
gui_idle_enable();