Skip to content

Commit

Permalink
pool: Fix treatment of async handle
Browse files Browse the repository at this point in the history
Signed-off-by: Cole Miller <[email protected]>
  • Loading branch information
cole-miller committed Aug 16, 2024
1 parent 3842e67 commit d500916
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/lib/threadpool.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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--;
}

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit d500916

Please sign in to comment.