diff options
| author | Garrett D'Amore <garrett@damore.org> | 2020-12-19 10:21:54 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2020-12-19 12:50:05 -0800 |
| commit | d12e169c1e733b255d146847ed57037b74681285 (patch) | |
| tree | e4a59142a6cf097dfdda8620635f173f53db9e7a /src/core/aio.c | |
| parent | 2033988343bce413763d3e9664e3e8372da48591 (diff) | |
| download | nng-d12e169c1e733b255d146847ed57037b74681285.tar.gz nng-d12e169c1e733b255d146847ed57037b74681285.tar.bz2 nng-d12e169c1e733b255d146847ed57037b74681285.zip | |
fixes #1372 nni_reap could be smaller
Diffstat (limited to 'src/core/aio.c')
| -rw-r--r-- | src/core/aio.c | 101 |
1 files changed, 20 insertions, 81 deletions
diff --git a/src/core/aio.c b/src/core/aio.c index b910a600..272f5e9d 100644 --- a/src/core/aio.c +++ b/src/core/aio.c @@ -19,13 +19,6 @@ static nni_thr nni_aio_expire_thr; static nni_list nni_aio_expire_list; static nni_aio *nni_aio_expire_aio; -// Reaping items. -static nni_thr nni_aio_reap_thr; -static nni_aio *nni_aio_reap_list; -static nni_mtx nni_aio_reap_lk; -static nni_cv nni_aio_reap_cv; -static bool nni_aio_reap_exit; - // Design notes. // // AIOs are only ever "completed" by the provider, which must call @@ -68,6 +61,11 @@ static bool nni_aio_reap_exit; // operations from starting, without waiting for any existing one to // complete, call nni_aio_close. +static nni_reap_list aio_reap_list = { + .rl_offset = offsetof(nni_aio, a_reap_node), + .rl_func = (nni_cb) nni_aio_free, +}; + static void nni_aio_expire_add(nni_aio *); void @@ -145,11 +143,7 @@ void nni_aio_reap(nni_aio *aio) { if (aio != NULL) { - nni_mtx_lock(&nni_aio_reap_lk); - aio->a_reap_next = nni_aio_reap_list; - nni_aio_reap_list = aio; - nni_cv_wake1(&nni_aio_reap_cv); - nni_mtx_unlock(&nni_aio_reap_lk); + nni_reap(&aio_reap_list, aio); } } @@ -549,41 +543,6 @@ nni_aio_expire_loop(void *unused) } } -static void -nni_aio_reap_loop(void *unused) -{ - NNI_ARG_UNUSED(unused); - - nni_thr_set_name(NULL, "nng:aio:reap"); - - nni_mtx_lock(&nni_aio_reap_lk); - - for (;;) { - nni_aio *aio; - - if ((aio = nni_aio_reap_list) == NULL) { - if (nni_aio_reap_exit) { - break; - } - - nni_cv_wait(&nni_aio_reap_cv); - continue; - } - nni_aio_reap_list = NULL; - nni_mtx_unlock(&nni_aio_reap_lk); - - while (aio != NULL) { - nni_aio *old = aio; - aio = aio->a_reap_next; - nni_aio_free(old); - } - - nni_mtx_lock(&nni_aio_reap_lk); - } - - nni_mtx_unlock(&nni_aio_reap_lk); -} - void * nni_aio_get_prov_extra(nni_aio *aio, unsigned index) { @@ -699,60 +658,40 @@ nni_sleep_aio(nng_duration ms, nng_aio *aio) void nni_aio_sys_fini(void) { - nni_mtx *mtx1 = &nni_aio_lk; - nni_cv * cv1 = &nni_aio_expire_cv; - nni_thr *thr1 = &nni_aio_expire_thr; - nni_mtx *mtx2 = &nni_aio_reap_lk; - nni_cv * cv2 = &nni_aio_reap_cv; - nni_thr *thr2 = &nni_aio_reap_thr; + nni_mtx *mtx = &nni_aio_lk; + nni_cv * cv = &nni_aio_expire_cv; + nni_thr *thr = &nni_aio_expire_thr; if (!nni_aio_expire_exit) { - nni_mtx_lock(mtx1); + nni_mtx_lock(mtx); nni_aio_expire_exit = true; - nni_cv_wake(cv1); - nni_mtx_unlock(mtx1); + nni_cv_wake(cv); + nni_mtx_unlock(mtx); } - if (!nni_aio_reap_exit) { - nni_mtx_lock(mtx2); - nni_aio_reap_exit = true; - nni_cv_wake(cv2); - nni_mtx_unlock(mtx2); - } - - nni_thr_fini(thr1); - nni_cv_fini(cv1); - nni_mtx_fini(mtx1); - - nni_thr_fini(thr2); - nni_cv_fini(cv2); - nni_mtx_fini(mtx2); + nni_thr_fini(thr); + nni_cv_fini(cv); + nni_mtx_fini(mtx); } int nni_aio_sys_init(void) { - int rv, rv1, rv2; - nni_thr *thr1 = &nni_aio_expire_thr; - nni_thr *thr2 = &nni_aio_reap_thr; + int rv; + nni_thr *thr = &nni_aio_expire_thr; NNI_LIST_INIT(&nni_aio_expire_list, nni_aio, a_expire_node); nni_mtx_init(&nni_aio_lk); nni_cv_init(&nni_aio_expire_cv, &nni_aio_lk); - nni_mtx_init(&nni_aio_reap_lk); - nni_cv_init(&nni_aio_reap_cv, &nni_aio_reap_lk); nni_aio_expire_exit = false; - nni_aio_reap_exit = false; - rv1 = nni_thr_init(thr1, nni_aio_expire_loop, NULL); - rv2 = nni_thr_init(thr2, nni_aio_reap_loop, NULL); - if (((rv = rv1) != 0) || ((rv = rv2) != 0)) { + rv = nni_thr_init(thr, nni_aio_expire_loop, NULL); + if (rv != 0) { nni_aio_sys_fini(); return (rv); } - nni_thr_run(thr1); - nni_thr_run(thr2); + nni_thr_run(thr); return (0); } |
