From 71e459eea31e9e47c0ce64a78e32b242d357f9a0 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sat, 7 Dec 2024 11:44:22 -0800 Subject: fini: add drain mechanism for aio, reap, and task subsystems Make sure *everything* is drained before proceeding all the way to deallocation. --- src/core/taskq.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/core/taskq.c') diff --git a/src/core/taskq.c b/src/core/taskq.c index 496c2fab..1f0ae1b6 100644 --- a/src/core/taskq.c +++ b/src/core/taskq.c @@ -59,6 +59,7 @@ nni_taskq_thread(void *self) continue; } + nni_cv_wake(&tq->tq_wait_cv); if (!tq->tq_run) { break; } @@ -127,6 +128,19 @@ nni_taskq_fini(nni_taskq *tq) NNI_FREE_STRUCT(tq); } +bool +nni_taskq_drain(nni_taskq *tq) +{ + bool result = false; + nni_mtx_lock(&tq->tq_mtx); + while (!nni_list_empty(&tq->tq_tasks)) { + result = true; + nni_cv_wait(&tq->tq_wait_cv); + } + nni_mtx_unlock(&tq->tq_mtx); + return (result); +} + void nni_task_exec(nni_task *task) { @@ -263,6 +277,12 @@ nni_taskq_sys_init(nng_init_params *params) return (nni_taskq_init(&nni_taskq_systq, (int) num_thr)); } +bool +nni_taskq_sys_drain(void) +{ + return (nni_taskq_drain(nni_taskq_systq)); +} + void nni_taskq_sys_fini(void) { -- cgit v1.2.3-70-g09d2