fix threadpool newapi

Sun, 09 Jun 2024 17:00:06 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 09 Jun 2024 17:00:06 +0200
branch
newapi
changeset 288
c5e89affb2ea
parent 287
5370ea7e45a2
child 289
6048b20bd46f

fix threadpool

ui/common/threadpool.c file | annotate | diff | comparison | revisions
--- 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 <pthread.h>
 
@@ -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;
 }
 

mercurial