From 6a44f9e1a17490806af19c5a4961b9d7226b93b0 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Sat, 30 Apr 2016 09:16:02 -0400 Subject: [PATCH] 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 --- core/audio.c | 2 +- core/collection.c | 6 +++--- core/containers/database.c | 2 +- core/idle.c | 3 +-- core/tempq.c | 2 +- gui/collection.c | 2 +- include/core/idle.h | 8 +++++++- tests/core/idle.c | 4 ++-- tests/gui/idle.c | 2 +- 9 files changed, 18 insertions(+), 13 deletions(-) diff --git a/core/audio.c b/core/audio.c index 8f6de007..ad362657 100644 --- a/core/audio.c +++ b/core/audio.c @@ -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() diff --git a/core/collection.c b/core/collection.c index 8c5ad2cf..13a69c65 100644 --- a/core/collection.c +++ b/core/collection.c @@ -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); } diff --git a/core/containers/database.c b/core/containers/database.c index 5df470aa..86a4f426 100644 --- a/core/containers/database.c +++ b/core/containers/database.c @@ -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) diff --git a/core/idle.c b/core/idle.c index 7b3a6a82..7d881c62 100644 --- a/core/idle.c +++ b/core/idle.c @@ -2,7 +2,6 @@ * Copyright 2013 (c) Anna Schumaker. */ #include - #include @@ -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; diff --git a/core/tempq.c b/core/tempq.c index c0a503d3..5ecd3413 100644 --- a/core/tempq.c +++ b/core/tempq.c @@ -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() diff --git a/gui/collection.c b/gui/collection.c index 0bc5e9ba..31dd97a9 100644 --- a/gui/collection.c +++ b/gui/collection.c @@ -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(); } diff --git a/include/core/idle.h b/include/core/idle.h index b9660ea3..dff12386 100644 --- a/include/core/idle.h +++ b/include/core/idle.h @@ -15,8 +15,14 @@ #define OCARINA_CORE_IDLE_H #include +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. diff --git a/tests/core/idle.c b/tests/core/idle.c index c7d5d8c7..c54d5c33 100644 --- a/tests/core/idle.c +++ b/tests/core/idle.c @@ -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(); diff --git a/tests/gui/idle.c b/tests/gui/idle.c index 02a1e6e2..c2cd1495 100644 --- a/tests/gui/idle.c +++ b/tests/gui/idle.c @@ -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();