core/idle: Don't allocate the thread pool unless we really need it
This saves ~75MB in my testing, and can be a useful memory savor for the case where all album art has been downloaded. Implements #96: Allocate g_thread_pool as needed Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
2a95031ee7
commit
042cddb65b
24
core/idle.c
24
core/idle.c
|
@ -10,8 +10,9 @@ struct idle_task {
|
||||||
void *idle_data;
|
void *idle_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
static GThreadPool *idle_pool = NULL;
|
static GThreadPool *idle_pool = NULL;
|
||||||
static GQueue idle_queue = G_QUEUE_INIT;
|
static GQueue idle_queue = G_QUEUE_INIT;
|
||||||
|
static enum idle_sync_t idle_mode = IDLE_SYNC;
|
||||||
static unsigned int queued = 0;
|
static unsigned int queued = 0;
|
||||||
static unsigned int serviced = 0;
|
static unsigned int serviced = 0;
|
||||||
|
|
||||||
|
@ -37,10 +38,9 @@ void __idle_thread(gpointer task, gpointer data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void idle_init(enum idle_sync_t idle_sync)
|
void idle_init(enum idle_sync_t sync)
|
||||||
{
|
{
|
||||||
if (idle_sync == IDLE_ASYNC)
|
idle_mode = sync;
|
||||||
idle_pool = g_thread_pool_new(__idle_thread, NULL, 1, true, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void idle_deinit()
|
void idle_deinit()
|
||||||
|
@ -52,8 +52,10 @@ void idle_deinit()
|
||||||
g_free(task);
|
g_free(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (idle_pool)
|
if (idle_pool) {
|
||||||
g_thread_pool_free(idle_pool, true, false);
|
g_thread_pool_free(idle_pool, true, true);
|
||||||
|
idle_pool = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
queued = 0;
|
queued = 0;
|
||||||
serviced = 0;
|
serviced = 0;
|
||||||
|
@ -63,7 +65,7 @@ void idle_schedule(enum idle_sync_t sync, bool (*func)(void *), void *data)
|
||||||
{
|
{
|
||||||
struct idle_task *task;
|
struct idle_task *task;
|
||||||
|
|
||||||
if (sync == IDLE_ASYNC && !idle_pool)
|
if (sync == IDLE_ASYNC && idle_mode == IDLE_SYNC)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
task = g_malloc(sizeof(struct idle_task));
|
task = g_malloc(sizeof(struct idle_task));
|
||||||
|
@ -72,8 +74,12 @@ void idle_schedule(enum idle_sync_t sync, bool (*func)(void *), void *data)
|
||||||
|
|
||||||
if (sync == IDLE_SYNC)
|
if (sync == IDLE_SYNC)
|
||||||
g_queue_push_tail(&idle_queue, task);
|
g_queue_push_tail(&idle_queue, task);
|
||||||
else
|
else {
|
||||||
|
if (!idle_pool)
|
||||||
|
idle_pool = g_thread_pool_new(__idle_thread, NULL, 1,
|
||||||
|
false, NULL);
|
||||||
g_thread_pool_push(idle_pool, task, NULL);
|
g_thread_pool_push(idle_pool, task, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
g_atomic_int_inc(&queued);
|
g_atomic_int_inc(&queued);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue