aboutsummaryrefslogtreecommitdiff
path: root/src/core/aio.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/aio.c')
-rw-r--r--src/core/aio.c55
1 files changed, 23 insertions, 32 deletions
diff --git a/src/core/aio.c b/src/core/aio.c
index a39c0118..fe9bcde8 100644
--- a/src/core/aio.c
+++ b/src/core/aio.c
@@ -56,20 +56,14 @@ static nni_list nni_aio_expire_aios;
static void nni_aio_expire_add(nni_aio *);
-int
+void
nni_aio_init(nni_aio *aio, nni_cb cb, void *arg)
{
- int rv;
-
memset(aio, 0, sizeof(*aio));
- if ((rv = nni_cv_init(&aio->a_cv, &nni_aio_lk)) != 0) {
- return (rv);
- }
+ nni_cv_init(&aio->a_cv, &nni_aio_lk);
aio->a_expire = NNI_TIME_NEVER;
aio->a_init = 1;
nni_task_init(NULL, &aio->a_task, cb, arg);
-
- return (0);
}
void
@@ -350,46 +344,43 @@ nni_aio_expire_loop(void *arg)
}
}
-int
-nni_aio_sys_init(void)
+void
+nni_aio_sys_fini(void)
{
- int rv;
nni_mtx *mtx = &nni_aio_lk;
nni_cv * cv = &nni_aio_expire_cv;
nni_thr *thr = &nni_aio_expire_thr;
- if (((rv = nni_mtx_init(mtx)) != 0) ||
- ((rv = nni_cv_init(cv, mtx)) != 0) ||
- ((rv = nni_thr_init(thr, nni_aio_expire_loop, NULL)) != 0)) {
- goto fail;
+ if (nni_aio_expire_run) {
+ nni_mtx_lock(mtx);
+ nni_aio_expire_run = 0;
+ nni_cv_wake(cv);
+ nni_mtx_unlock(mtx);
}
- NNI_LIST_INIT(&nni_aio_expire_aios, nni_aio, a_expire_node);
- nni_aio_expire_run = 1;
- nni_thr_run(thr);
- return (0);
-fail:
nni_thr_fini(thr);
nni_cv_fini(cv);
nni_mtx_fini(mtx);
- return (rv);
}
-void
-nni_aio_sys_fini(void)
+int
+nni_aio_sys_init(void)
{
+ int rv;
nni_mtx *mtx = &nni_aio_lk;
nni_cv * cv = &nni_aio_expire_cv;
nni_thr *thr = &nni_aio_expire_thr;
- if (nni_aio_expire_run) {
- nni_mtx_lock(mtx);
- nni_aio_expire_run = 0;
- nni_cv_wake(cv);
- nni_mtx_unlock(mtx);
+ NNI_LIST_INIT(&nni_aio_expire_aios, nni_aio, a_expire_node);
+ nni_mtx_init(mtx);
+ nni_cv_init(cv, mtx);
+
+ if ((rv = nni_thr_init(thr, nni_aio_expire_loop, NULL)) != 0) {
+ nni_aio_sys_fini();
+ return (rv);
}
- nni_thr_fini(thr);
- nni_cv_fini(cv);
- nni_mtx_fini(mtx);
-} \ No newline at end of file
+ nni_aio_expire_run = 1;
+ nni_thr_run(thr);
+ return (0);
+}