ui/common/threadpool.h

changeset 950
39641cf150eb
parent 949
ef8f13c8c08f
--- a/ui/common/threadpool.h	Sat Dec 06 14:12:11 2025 +0100
+++ b/ui/common/threadpool.h	Sat Dec 06 15:24:13 2025 +0100
@@ -39,6 +39,8 @@
 extern "C" {
 #endif
     
+typedef struct UiQueueElm UiQueueElm;
+typedef struct UiQueue    UiQueue;
     
 typedef struct UiJob {
     UiObject      *obj;
@@ -48,22 +50,30 @@
     void          *finish_data;
 } UiJob;
     
+struct UiQueueElm {
+    void       *data;
+    UiQueueElm *next;
+};
+
+struct UiQueue {
+    UiQueueElm      *elements;
+    size_t          length;
+    pthread_mutex_t lock;
+    pthread_mutex_t avlbl_lock;
+    pthread_cond_t  available;
+};
     
 typedef struct  _threadpool_job   threadpool_job;
 typedef void*(*job_callback_f)(void *data);
     
 typedef struct _pool_queue pool_queue_t;
 struct UiThreadpool {
-    pthread_mutex_t queue_lock;
-    pthread_mutex_t avlbl_lock;
-    pthread_cond_t  available;
-    pool_queue_t    *queue;
-    uint32_t        queue_len;
-    uint32_t        num_idle;
-    int             min_threads;
-    int             max_threads;
-    pthread_t       *threads;
-    int             nthreads;
+    UiQueue   *queue;
+    uint32_t  num_idle;
+    int       min_threads;
+    int       max_threads;
+    pthread_t *threads;
+    int       nthreads;
 };
 
 struct _threadpool_job {
@@ -82,7 +92,11 @@
 void* threadpool_func(void *data);
 threadpool_job* threadpool_get_job(UiThreadpool *pool);
 void threadpool_run(UiThreadpool *pool, job_callback_f func, void *data);
-void threadpool_enqueue_job(UiThreadpool *pool, threadpool_job *job);
+
+UiQueue* ui_queue_create(void);
+void ui_queue_free(UiQueue *queue);
+void ui_queue_put(UiQueue *queue, void *data);
+void* ui_queue_get_wait(UiQueue *queue);
 
 #ifdef __cplusplus
 }

mercurial