| 37 |
37 |
| 38 #ifdef __cplusplus |
38 #ifdef __cplusplus |
| 39 extern "C" { |
39 extern "C" { |
| 40 #endif |
40 #endif |
| 41 |
41 |
| |
42 typedef struct UiQueueElm UiQueueElm; |
| |
43 typedef struct UiQueue UiQueue; |
| 42 |
44 |
| 43 typedef struct UiJob { |
45 typedef struct UiJob { |
| 44 UiObject *obj; |
46 UiObject *obj; |
| 45 ui_threadfunc job_func; |
47 ui_threadfunc job_func; |
| 46 void *job_data; |
48 void *job_data; |
| 47 ui_callback finish_callback; |
49 ui_callback finish_callback; |
| 48 void *finish_data; |
50 void *finish_data; |
| 49 } UiJob; |
51 } UiJob; |
| 50 |
52 |
| |
53 struct UiQueueElm { |
| |
54 void *data; |
| |
55 UiQueueElm *next; |
| |
56 }; |
| |
57 |
| |
58 struct UiQueue { |
| |
59 UiQueueElm *elements; |
| |
60 size_t length; |
| |
61 pthread_mutex_t lock; |
| |
62 pthread_mutex_t avlbl_lock; |
| |
63 pthread_cond_t available; |
| |
64 }; |
| 51 |
65 |
| 52 typedef struct _threadpool_job threadpool_job; |
66 typedef struct _threadpool_job threadpool_job; |
| 53 typedef void*(*job_callback_f)(void *data); |
67 typedef void*(*job_callback_f)(void *data); |
| 54 |
68 |
| 55 typedef struct _pool_queue pool_queue_t; |
69 typedef struct _pool_queue pool_queue_t; |
| 56 struct UiThreadpool { |
70 struct UiThreadpool { |
| 57 pthread_mutex_t queue_lock; |
71 UiQueue *queue; |
| 58 pthread_mutex_t avlbl_lock; |
72 uint32_t num_idle; |
| 59 pthread_cond_t available; |
73 int min_threads; |
| 60 pool_queue_t *queue; |
74 int max_threads; |
| 61 uint32_t queue_len; |
75 pthread_t *threads; |
| 62 uint32_t num_idle; |
76 int nthreads; |
| 63 int min_threads; |
|
| 64 int max_threads; |
|
| 65 pthread_t *threads; |
|
| 66 int nthreads; |
|
| 67 }; |
77 }; |
| 68 |
78 |
| 69 struct _threadpool_job { |
79 struct _threadpool_job { |
| 70 job_callback_f callback; |
80 job_callback_f callback; |
| 71 void *data; |
81 void *data; |
| 80 int threadpool_start(UiThreadpool *pool); |
90 int threadpool_start(UiThreadpool *pool); |
| 81 int threadpool_join(UiThreadpool *pool); |
91 int threadpool_join(UiThreadpool *pool); |
| 82 void* threadpool_func(void *data); |
92 void* threadpool_func(void *data); |
| 83 threadpool_job* threadpool_get_job(UiThreadpool *pool); |
93 threadpool_job* threadpool_get_job(UiThreadpool *pool); |
| 84 void threadpool_run(UiThreadpool *pool, job_callback_f func, void *data); |
94 void threadpool_run(UiThreadpool *pool, job_callback_f func, void *data); |
| 85 void threadpool_enqueue_job(UiThreadpool *pool, threadpool_job *job); |
95 |
| |
96 UiQueue* ui_queue_create(void); |
| |
97 void ui_queue_free(UiQueue *queue); |
| |
98 void ui_queue_put(UiQueue *queue, void *data); |
| |
99 void* ui_queue_get_wait(UiQueue *queue); |
| 86 |
100 |
| 87 #ifdef __cplusplus |
101 #ifdef __cplusplus |
| 88 } |
102 } |
| 89 #endif |
103 #endif |
| 90 |
104 |