src/server/util/thrpool.c

changeset 556
b036ccad4b49
parent 408
56edda8701e0
equal deleted inserted replaced
555:66b0accda0a8 556:b036ccad4b49
76 76
77 job->callback(job->data); 77 job->callback(job->data);
78 78
79 free(job); 79 free(job);
80 } 80 }
81 ws_atomic_dec32(&pool->num_threads); 81 uint32_t nthreads = ws_atomic_dec32(&pool->num_threads);
82 if(nthreads == 0) {
83 log_ereport(LOG_INFORM, "threadpool closed"); // TODO: log threadpool name
84 }
82 return NULL; 85 return NULL;
83 } 86 }
84 87
85 threadpool_job* threadpool_get_job(threadpool_t *pool) { 88 threadpool_job* threadpool_get_job(threadpool_t *pool) {
86 pthread_mutex_lock(&pool->queue_lock); 89 pthread_mutex_lock(&pool->queue_lock);
160 } 163 }
161 last_elem->next = q; 164 last_elem->next = q;
162 } 165 }
163 pool->queue_len++; 166 pool->queue_len++;
164 } 167 }
168
169 void threadpool_shutdown(threadpool_t *pool) {
170 int nthreads = pool->max_threads;
171 for(int i=0;i<nthreads;i++) {
172 pthread_mutex_lock(&pool->queue_lock);
173 threadpool_enqueue_job(pool, &kill_job);
174 pthread_cond_signal(&pool->available);
175 pthread_mutex_unlock(&pool->queue_lock);
176 }
177 }

mercurial