Lines 420-427
static int pthreadpool_stop_locked(struct pthreadpool
Link Here
|
420 |
*/ |
420 |
*/ |
421 |
|
421 |
|
422 |
ret = pthread_cond_broadcast(&pool->condvar); |
422 |
ret = pthread_cond_broadcast(&pool->condvar); |
|
|
423 |
if (ret != 0) { |
424 |
return ret; |
425 |
} |
423 |
|
426 |
|
424 |
return ret; |
427 |
do { |
|
|
428 |
ret = pthread_cond_wait(&pool->condvar, &pool->mutex); |
429 |
assert(ret == 0); |
430 |
} while (pool->num_threads > 0); |
431 |
|
432 |
return 0; |
425 |
} |
433 |
} |
426 |
|
434 |
|
427 |
/* |
435 |
/* |
Lines 448-461
int pthreadpool_stop(struct pthreadpool *pool)
Link Here
|
448 |
} |
456 |
} |
449 |
|
457 |
|
450 |
/* |
458 |
/* |
451 |
* Destroy a thread pool. Wake up all idle threads for exit. The last |
459 |
* Destroy a thread pool. Wake up all idle threads for exit. |
452 |
* one will free the pool. |
|
|
453 |
*/ |
460 |
*/ |
454 |
|
461 |
|
455 |
int pthreadpool_destroy(struct pthreadpool *pool) |
462 |
int pthreadpool_destroy(struct pthreadpool *pool) |
456 |
{ |
463 |
{ |
457 |
int ret, ret1; |
464 |
int ret, ret1; |
458 |
bool free_it; |
|
|
459 |
|
465 |
|
460 |
assert(!pool->destroyed); |
466 |
assert(!pool->destroyed); |
461 |
|
467 |
|
Lines 470-483
int pthreadpool_destroy(struct pthreadpool *pool)
Link Here
|
470 |
ret = pthreadpool_stop_locked(pool); |
476 |
ret = pthreadpool_stop_locked(pool); |
471 |
} |
477 |
} |
472 |
|
478 |
|
473 |
free_it = (pool->num_threads == 0); |
|
|
474 |
|
475 |
ret1 = pthread_mutex_unlock(&pool->mutex); |
479 |
ret1 = pthread_mutex_unlock(&pool->mutex); |
476 |
assert(ret1 == 0); |
480 |
assert(ret1 == 0); |
477 |
|
481 |
|
478 |
if (free_it) { |
482 |
pthreadpool_free(pool); |
479 |
pthreadpool_free(pool); |
|
|
480 |
} |
481 |
|
483 |
|
482 |
return ret; |
484 |
return ret; |
483 |
} |
485 |
} |
Lines 489-506
static void pthreadpool_server_exit(struct pthreadpool
Link Here
|
489 |
static void pthreadpool_server_exit(struct pthreadpool *pool) |
491 |
static void pthreadpool_server_exit(struct pthreadpool *pool) |
490 |
{ |
492 |
{ |
491 |
int ret; |
493 |
int ret; |
492 |
bool free_it; |
|
|
493 |
|
494 |
|
494 |
pool->num_threads -= 1; |
495 |
pool->num_threads -= 1; |
495 |
|
496 |
|
496 |
free_it = (pool->destroyed && (pool->num_threads == 0)); |
497 |
if (pool->num_threads == 0) { |
|
|
498 |
ret = pthread_cond_broadcast(&pool->condvar); |
499 |
assert(ret == 0); |
500 |
} |
497 |
|
501 |
|
498 |
ret = pthread_mutex_unlock(&pool->mutex); |
502 |
ret = pthread_mutex_unlock(&pool->mutex); |
499 |
assert(ret == 0); |
503 |
assert(ret == 0); |
500 |
|
|
|
501 |
if (free_it) { |
502 |
pthreadpool_free(pool); |
503 |
} |
504 |
} |
504 |
} |
505 |
|
505 |
|
506 |
static bool pthreadpool_get_job(struct pthreadpool *p, |
506 |
static bool pthreadpool_get_job(struct pthreadpool *p, |