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:
parent
a6bfbbb1c6
commit
6a44f9e1a1
|
@ -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);
|
audio_bus = gst_bus_add_watch(bus, __audio_message, NULL);
|
||||||
gst_object_unref(bus);
|
gst_object_unref(bus);
|
||||||
|
|
||||||
idle_schedule(__audio_init_idle, NULL);
|
idle_schedule(IDLE_SYNC, __audio_init_idle, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void audio_deinit()
|
void audio_deinit()
|
||||||
|
|
|
@ -42,7 +42,7 @@ static void __scan_dir_later(struct library *library, const gchar *dir)
|
||||||
data->sd_path = g_strdup(dir);
|
data->sd_path = g_strdup(dir);
|
||||||
|
|
||||||
/* data is freed by __scan_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)
|
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)
|
void collection_init(struct queue_ops *ops)
|
||||||
{
|
{
|
||||||
queue_init(&c_queue, Q_ENABLED | Q_REPEAT | Q_ADD_FRONT, 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()
|
void collection_deinit()
|
||||||
|
@ -211,7 +211,7 @@ void collection_update(struct library *library)
|
||||||
if (!library)
|
if (!library)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
idle_schedule(__validate_library, library);
|
idle_schedule(IDLE_SYNC, __validate_library, library);
|
||||||
__scan_dir_later(library, library->li_path);
|
__scan_dir_later(library, library->li_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -131,7 +131,7 @@ void db_load(struct database *db)
|
||||||
|
|
||||||
void db_load_idle(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)
|
struct db_entry *db_insert(struct database *db, const gchar *key)
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
* Copyright 2013 (c) Anna Schumaker.
|
* Copyright 2013 (c) Anna Schumaker.
|
||||||
*/
|
*/
|
||||||
#include <core/idle.h>
|
#include <core/idle.h>
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,7 +15,7 @@ static float queued = 0.0;
|
||||||
static float serviced = 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));
|
struct idle_task *task = g_malloc(sizeof(struct idle_task));
|
||||||
task->idle_func = func;
|
task->idle_func = func;
|
||||||
|
|
|
@ -74,7 +74,7 @@ static void __tempq_init_idle(void *data)
|
||||||
void tempq_init(struct queue_ops *ops)
|
void tempq_init(struct queue_ops *ops)
|
||||||
{
|
{
|
||||||
tempq_ops = ops;
|
tempq_ops = ops;
|
||||||
idle_schedule(__tempq_init_idle, NULL);
|
idle_schedule(IDLE_SYNC, __tempq_init_idle, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tempq_deinit()
|
void tempq_deinit()
|
||||||
|
|
|
@ -231,7 +231,7 @@ void gui_collection_init()
|
||||||
gtk_tree_view_get_selection(treeview),
|
gtk_tree_view_get_selection(treeview),
|
||||||
gui_sidebar_on_select, NULL, NULL);
|
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_sidebar_set_size(gui_queue(collection_get_queue()));
|
||||||
gui_idle_enable();
|
gui_idle_enable();
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,14 @@
|
||||||
#define OCARINA_CORE_IDLE_H
|
#define OCARINA_CORE_IDLE_H
|
||||||
#include <stdbool.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. */
|
/* 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.
|
* Called to run the next task on the idle queue.
|
||||||
|
|
|
@ -25,7 +25,7 @@ static void test_idle_queue(unsigned int n)
|
||||||
test_equal(idle_run_task(), (bool)false);
|
test_equal(idle_run_task(), (bool)false);
|
||||||
|
|
||||||
for (unsigned int i = 0; i < n; i++)
|
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);
|
test_equal(idle_progress(), (float)0.0);
|
||||||
|
|
||||||
for (unsigned int i = 0; i < (n - 1); i++) {
|
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);
|
test_equal(idle_progress(), (float)1.0);
|
||||||
|
|
||||||
for (unsigned int i = 0; i < n; i++)
|
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);
|
test_equal(idle_progress(), (float)0.0);
|
||||||
|
|
||||||
idle_cancel();
|
idle_cancel();
|
||||||
|
|
|
@ -52,7 +52,7 @@ static void test_idle()
|
||||||
test_equal(gtk_widget_is_visible(GTK_WIDGET(progress)), false);
|
test_equal(gtk_widget_is_visible(GTK_WIDGET(progress)), false);
|
||||||
|
|
||||||
for (i = 0; i < N; i++)
|
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();
|
gui_idle_enable();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue