ui/common/threadpool.c

changeset 949
ef8f13c8c08f
parent 659
d6baaa93f7be
child 950
39641cf150eb
equal deleted inserted replaced
948:94bc57d63128 949:ef8f13c8c08f
52 52
53 return pool; 53 return pool;
54 } 54 }
55 55
56 int threadpool_start(UiThreadpool *pool) { 56 int threadpool_start(UiThreadpool *pool) {
57 pool->nthreads = pool->min_threads;
58 pool->threads = calloc(pool->max_threads, sizeof(pthread_t));
57 /* create pool threads */ 59 /* create pool threads */
58 for(int i=0;i<pool->min_threads;i++) { 60 for(int i=0;i<pool->nthreads;i++) {
59 pthread_t t; 61 if (pthread_create(&pool->threads[i], NULL, threadpool_func, pool) != 0) {
60 if (pthread_create(&t, NULL, threadpool_func, pool) != 0) {
61 fprintf(stderr, "uic: threadpool_start: pthread_create failed: %s", strerror(errno)); 62 fprintf(stderr, "uic: threadpool_start: pthread_create failed: %s", strerror(errno));
62 return 1; 63 return 1;
63 } 64 }
64 } 65 }
65 return 0; 66 return 0;
67 }
68
69 int threadpool_join(UiThreadpool *pool) {
70 int err = 0;
71 for(int i=0;i<pool->nthreads;i++) {
72 if(pthread_join(pool->threads[i], NULL)) {
73 err = 1;
74 }
75 }
76 return err;
66 } 77 }
67 78
68 void* threadpool_func(void *data) { 79 void* threadpool_func(void *data) {
69 UiThreadpool *pool = (UiThreadpool*)data; 80 UiThreadpool *pool = (UiThreadpool*)data;
70 81

mercurial