aboutsummaryrefslogtreecommitdiff
path: root/src/core/aio.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/aio.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/aio.c')
-rw-r--r--src/core/aio.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/core/aio.c b/src/core/aio.c
index 5807869b..bb8347dd 100644
--- a/src/core/aio.c
+++ b/src/core/aio.c
@@ -780,15 +780,21 @@ nni_sleep_aio(nng_duration ms, nng_aio *aio)
}
}
-static void
+static bool
nni_aio_expire_q_stop(nni_aio_expire_q *eq)
{
- if (eq != NULL && !eq->eq_stop) {
+ bool result = false;
+ if (eq != NULL) {
nni_mtx_lock(&eq->eq_mtx);
eq->eq_stop = true;
nni_cv_wake(&eq->eq_cv);
+ while (!nni_list_empty(&eq->eq_list)) {
+ result = true;
+ nni_cv_wait(&eq->eq_cv);
+ }
nni_mtx_unlock(&eq->eq_mtx);
}
+ return (result);
}
static void
@@ -834,12 +840,16 @@ nni_aio_expire_q_alloc(void)
return (eq);
}
-void
-nni_aio_sys_stop(void)
+bool
+nni_aio_sys_drain(void)
{
+ bool result = false;
for (int i = 0; i < nni_aio_expire_q_cnt; i++) {
- nni_aio_expire_q_stop(nni_aio_expire_q_list[i]);
+ if (nni_aio_expire_q_stop(nni_aio_expire_q_list[i])) {
+ result = true;
+ }
}
+ return (result);
}
void