aboutsummaryrefslogtreecommitdiff
path: root/src/core/taskq.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2024-12-07 11:44:22 -0800
committerGarrett D'Amore <garrett@damore.org>2024-12-07 11:56:22 -0800
commit71e459eea31e9e47c0ce64a78e32b242d357f9a0 (patch)
treec4f6608066aaa6505a5625f399c94845abe6c162 /src/core/taskq.c
parent8fa3b2aa8e9191669f137be39ba61ad39243483a (diff)
downloadnng-71e459eea31e9e47c0ce64a78e32b242d357f9a0.tar.gz
nng-71e459eea31e9e47c0ce64a78e32b242d357f9a0.tar.bz2
nng-71e459eea31e9e47c0ce64a78e32b242d357f9a0.zip
fini: add drain mechanism for aio, reap, and task subsystems
Make sure *everything* is drained before proceeding all the way to deallocation.
Diffstat (limited to 'src/core/taskq.c')
-rw-r--r--src/core/taskq.c20
1 files changed, 20 insertions, 0 deletions
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)
{