diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-08-07 16:12:41 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-08-07 16:12:41 -0700 |
| commit | 22d991fda77578dd03c8d477f8427631e6383cee (patch) | |
| tree | c81eb35a13fbeb1dab8f8e6ca62dc8ccf42636e0 /src/core/aio.c | |
| parent | c5354ea49184a359df8d477e844b1c52aeb234d5 (diff) | |
| download | nng-22d991fda77578dd03c8d477f8427631e6383cee.tar.gz nng-22d991fda77578dd03c8d477f8427631e6383cee.tar.bz2 nng-22d991fda77578dd03c8d477f8427631e6383cee.zip | |
Subsystem initialize is idempotent; simplify cleanup.
Diffstat (limited to 'src/core/aio.c')
| -rw-r--r-- | src/core/aio.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/core/aio.c b/src/core/aio.c index 792b63f2..273ce22e 100644 --- a/src/core/aio.c +++ b/src/core/aio.c @@ -14,7 +14,7 @@ static nni_mtx nni_aio_lk; // These are used for expiration. static nni_cv nni_aio_expire_cv; -static int nni_aio_expire_exit; +static int nni_aio_expire_run; static nni_thr nni_aio_expire_thr; static nni_list nni_aio_expire_aios; @@ -295,7 +295,7 @@ nni_aio_expire_loop(void *arg) for (;;) { nni_mtx_lock(&nni_aio_lk); - if (nni_aio_expire_exit) { + if (nni_aio_expire_run == 0) { nni_mtx_unlock(&nni_aio_lk); return; } @@ -358,6 +358,7 @@ nni_aio_sys_init(void) goto fail; } NNI_LIST_INIT(&nni_aio_expire_aios, nni_aio, a_expire_node); + nni_aio_expire_run = 1; nni_thr_run(thr); return (0); @@ -375,10 +376,12 @@ nni_aio_sys_fini(void) nni_cv * cv = &nni_aio_expire_cv; nni_thr *thr = &nni_aio_expire_thr; - nni_mtx_lock(mtx); - nni_aio_expire_exit = 1; - nni_cv_wake(cv); - nni_mtx_unlock(mtx); + if (nni_aio_expire_run) { + nni_mtx_lock(mtx); + nni_aio_expire_run = 0; + nni_cv_wake(cv); + nni_mtx_unlock(mtx); + } nni_thr_fini(thr); nni_cv_fini(cv); |
