diff --git a/src/lib/threadpool.c b/src/lib/threadpool.c index f87577184..08c18ec07 100644 --- a/src/lib/threadpool.c +++ b/src/lib/threadpool.c @@ -143,9 +143,9 @@ static inline bool pool_is_inited(const pool_t *pool) return pool->pi != NULL; } -static inline bool has_active_ws(pool_t *pool) +static inline bool has_active_ws(pool_impl_t *pi) { - return pool->pi->active_ws > 0; + return pi->active_ws > 0; } static inline void w_register(pool_t *pool, pool_work_t *w) @@ -158,7 +158,7 @@ static inline void w_register(pool_t *pool, pool_work_t *w) static inline void w_unregister(pool_t *pool, pool_work_t *w) { (void)w; - PRE(has_active_ws(pool)); + PRE(has_active_ws(pool->pi)); pool->pi->active_ws--; } @@ -565,10 +565,12 @@ int pool_init(pool_t *pool, free(pi); return rc; } + pi->outq_async.data = pi; static uv_once_t once = UV_ONCE_INIT; uv_once(&once, thread_key_create); if (thread_key_create_err != 0) { + /* FIXME callback here */ uv_close((uv_handle_t *)&pi->outq_async, NULL); uv_mutex_destroy(&pi->outq_mutex); free(pi); @@ -580,26 +582,31 @@ int pool_init(pool_t *pool, return 0; } -void pool_fini(pool_t *pool) +void pool_fini_cb(uv_handle_t *a) { - pool_impl_t *pi = pool->pi; - - pool_cleanup(pool); + pool_impl_t *pi = a->data; uv_mutex_lock(&pi->outq_mutex); - POST(!!(pool->flags & POOL_FOR_UT_NON_CLEAN_FINI) || - (empty(&pi->outq) && !has_active_ws(pool))); + POST(empty(&pi->outq) && !has_active_ws(pi)); uv_mutex_unlock(&pi->outq_mutex); uv_mutex_destroy(&pi->outq_mutex); free(pi); } +void pool_fini(pool_t *pool) +{ + pool_impl_t *pi = pool->pi; + + pool_cleanup(pool); + + uv_close((uv_handle_t *)&pi->outq_async, pool_fini_cb); +} + void pool_close(pool_t *pool) { pool_impl_t *pi = pool->pi; - uv_close((uv_handle_t *)&pi->outq_async, NULL); uv_mutex_lock(&pi->mutex); pi->exiting = true; uv_mutex_unlock(&pi->mutex);