# HG changeset patch # User Olaf Wintermann # Date 1717945206 -7200 # Node ID c5e89affb2ea55375b2334e9b6562acda4f75494 # Parent 5370ea7e45a21e3004a3ed3e0f810778e446580c fix threadpool diff -r 5370ea7e45a2 -r c5e89affb2ea ui/common/threadpool.c --- a/ui/common/threadpool.c Sun Jun 09 16:26:28 2024 +0200 +++ b/ui/common/threadpool.c Sun Jun 09 17:00:06 2024 +0200 @@ -27,6 +27,7 @@ */ #include "threadpool.h" +#include "context.h" #include @@ -70,7 +71,7 @@ if(job == &kill_job) { break; } - + job->callback(job->data); free(job); @@ -145,17 +146,35 @@ UiThreadpool* ui_threadpool_create(int nthreads) { - return threadpool_new(nthreads, nthreads); + UiThreadpool *pool = threadpool_new(nthreads, nthreads); + threadpool_start(pool); // TODO: check return value + return pool; } void ui_threadpool_destroy(UiThreadpool* pool) { } +static int ui_threadpool_job_finish(void *data) { + UiJob *job = data; + UiEvent event; + event.obj = job->obj; + event.window = job->obj->window; + event.document = job->obj->ctx->document; + event.intval = 0; + event.eventdata = NULL; + job->finish_callback(&event, job->finish_data); + free(job); + return 0; +} + static void* ui_threadpool_job_func(void *data) { UiJob *job = data; - - free(job); + if (!job->job_func(job->job_data) && job->finish_callback) { + ui_call_mainthread(ui_threadpool_job_finish, job); + } else { + free(job); + } return NULL; }