252 time_t end = t + timeout; |
252 time_t end = t + timeout; |
253 int i = 0; |
253 int i = 0; |
254 while(t < end || i < 2) { |
254 while(t < end || i < 2) { |
255 uint32_t num_threads = pool->num_threads; |
255 uint32_t num_threads = pool->num_threads; |
256 if(num_threads == 0) { |
256 if(num_threads == 0) { |
257 // it's possible that we send too many kill jobs, cleanup the queue |
|
258 while(pool->queue) { |
|
259 pool_queue_t *q = pool->queue->next; |
|
260 free(pool->queue); |
|
261 pool->queue = q; |
|
262 } |
|
263 break; |
257 break; |
264 } |
258 } |
265 |
259 |
266 log_ereport(LOG_VERBOSE, "threadpool_shutdown: wait for thread shutdown: %u threads still running", (unsigned int)num_threads); |
260 log_ereport(LOG_VERBOSE, "threadpool_shutdown: wait for thread shutdown: %u threads still running", (unsigned int)num_threads); |
267 sleep(5); |
261 sleep(5); |
268 i++; |
262 i++; |
269 t = time(NULL); |
263 t = time(NULL); |
270 } |
264 } |
271 |
265 |
272 if(pool->num_threads) { |
266 if(pool->num_threads == 0) { |
|
267 // it's possible that we send too many kill jobs, cleanup the queue |
|
268 while(pool->queue) { |
|
269 pool_queue_t *q = pool->queue->next; |
|
270 free(pool->queue); |
|
271 pool->queue = q; |
|
272 } |
|
273 |
|
274 free(pool->threads); |
|
275 free(pool->thrstatus); |
|
276 free(pool); |
|
277 |
273 log_ereport(LOG_VERBOSE, "threadpool_shutdown successful"); |
278 log_ereport(LOG_VERBOSE, "threadpool_shutdown successful"); |
274 } else if(t > end) { |
279 } else if(t > end) { |
275 log_ereport(LOG_WARN, "threadpool_shutdown: timeout"); |
280 log_ereport(LOG_WARN, "threadpool_shutdown: timeout"); |
276 } |
281 } |
277 } |
282 } |