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
20
core/idle.c
20
core/idle.c
|
@ -12,6 +12,7 @@ struct idle_task {
|
|||
|
||||
static GThreadPool *idle_pool = NULL;
|
||||
static GQueue idle_queue = G_QUEUE_INIT;
|
||||
static enum idle_sync_t idle_mode = IDLE_SYNC;
|
||||
static unsigned int queued = 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_pool = g_thread_pool_new(__idle_thread, NULL, 1, true, NULL);
|
||||
idle_mode = sync;
|
||||
}
|
||||
|
||||
void idle_deinit()
|
||||
|
@ -52,8 +52,10 @@ void idle_deinit()
|
|||
g_free(task);
|
||||
}
|
||||
|
||||
if (idle_pool)
|
||||
g_thread_pool_free(idle_pool, true, false);
|
||||
if (idle_pool) {
|
||||
g_thread_pool_free(idle_pool, true, true);
|
||||
idle_pool = NULL;
|
||||
}
|
||||
|
||||
queued = 0;
|
||||
serviced = 0;
|
||||
|
@ -63,7 +65,7 @@ void idle_schedule(enum idle_sync_t sync, bool (*func)(void *), void *data)
|
|||
{
|
||||
struct idle_task *task;
|
||||
|
||||
if (sync == IDLE_ASYNC && !idle_pool)
|
||||
if (sync == IDLE_ASYNC && idle_mode == IDLE_SYNC)
|
||||
return;
|
||||
|
||||
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)
|
||||
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_atomic_int_inc(&queued);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue