ui/common/threadpool.c

branch
newapi
changeset 288
c5e89affb2ea
parent 280
e3565cf7c831
equal deleted inserted replaced
287:5370ea7e45a2 288:c5e89affb2ea
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 #include "threadpool.h" 29 #include "threadpool.h"
30 #include "context.h"
30 31
31 #include <pthread.h> 32 #include <pthread.h>
32 33
33 #ifndef _WIN32 34 #ifndef _WIN32
34 35
68 for(;;) { 69 for(;;) {
69 threadpool_job *job = threadpool_get_job(pool); 70 threadpool_job *job = threadpool_get_job(pool);
70 if(job == &kill_job) { 71 if(job == &kill_job) {
71 break; 72 break;
72 } 73 }
73 74
74 job->callback(job->data); 75 job->callback(job->data);
75 76
76 free(job); 77 free(job);
77 } 78 }
78 return NULL; 79 return NULL;
143 144
144 145
145 146
146 147
147 UiThreadpool* ui_threadpool_create(int nthreads) { 148 UiThreadpool* ui_threadpool_create(int nthreads) {
148 return threadpool_new(nthreads, nthreads); 149 UiThreadpool *pool = threadpool_new(nthreads, nthreads);
150 threadpool_start(pool); // TODO: check return value
151 return pool;
149 } 152 }
150 153
151 void ui_threadpool_destroy(UiThreadpool* pool) { 154 void ui_threadpool_destroy(UiThreadpool* pool) {
152 155
153 } 156 }
154 157
158 static int ui_threadpool_job_finish(void *data) {
159 UiJob *job = data;
160 UiEvent event;
161 event.obj = job->obj;
162 event.window = job->obj->window;
163 event.document = job->obj->ctx->document;
164 event.intval = 0;
165 event.eventdata = NULL;
166 job->finish_callback(&event, job->finish_data);
167 free(job);
168 return 0;
169 }
170
155 static void* ui_threadpool_job_func(void *data) { 171 static void* ui_threadpool_job_func(void *data) {
156 UiJob *job = data; 172 UiJob *job = data;
157 173 if (!job->job_func(job->job_data) && job->finish_callback) {
158 free(job); 174 ui_call_mainthread(ui_threadpool_job_finish, job);
175 } else {
176 free(job);
177 }
159 return NULL; 178 return NULL;
160 } 179 }
161 180
162 void ui_threadpool_job(UiThreadpool* pool, UiObject* obj, ui_threadfunc tf, void* td, ui_callback f, void* fd) { 181 void ui_threadpool_job(UiThreadpool* pool, UiObject* obj, ui_threadfunc tf, void* td, ui_callback f, void* fd) {
163 UiJob* job = malloc(sizeof(UiJob)); 182 UiJob* job = malloc(sizeof(UiJob));

mercurial