From 3fd43c488b47874db22a87a1d87eed94bbd85725 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sun, 1 Jan 2017 14:34:29 -0800 Subject: Pipe simplifications for thread management. This may also address a race in closing down pipes. Now pipes are always registered with the socket. They also always have both a sender and receiver thread. If the protocol doesn't need one or the other, the stock thread just exits early. --- src/core/thread.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src/core/thread.c') diff --git a/src/core/thread.c b/src/core/thread.c index 4f714341..d1f46e3f 100644 --- a/src/core/thread.c +++ b/src/core/thread.c @@ -15,48 +15,56 @@ nni_mtx_init(nni_mtx *mtx) return (nni_plat_mtx_init(&mtx->mtx)); } + void nni_mtx_fini(nni_mtx *mtx) { nni_plat_mtx_fini(&mtx->mtx); } + void nni_mtx_lock(nni_mtx *mtx) { nni_plat_mtx_lock(&mtx->mtx); } + void nni_mtx_unlock(nni_mtx *mtx) { nni_plat_mtx_unlock(&mtx->mtx); } + int nni_mtx_trylock(nni_mtx *mtx) { return (nni_plat_mtx_trylock(&mtx->mtx)); } + int nni_cv_init(nni_cv *cv, nni_mtx *mtx) { return (nni_plat_cv_init(&cv->cv, &mtx->mtx)); } + void nni_cv_fini(nni_cv *cv) { nni_plat_cv_fini(&cv->cv); } + void nni_cv_wait(nni_cv *cv) { nni_plat_cv_wait(&cv->cv); } + int nni_cv_until(nni_cv *cv, nni_time until) { @@ -73,12 +81,14 @@ nni_cv_until(nni_cv *cv, nni_time until) return (nni_plat_cv_until(&cv->cv, until)); } + void nni_cv_wake(nni_cv *cv) { return (nni_plat_cv_wake(&cv->cv)); } + static void nni_thr_wrap(void *arg) { @@ -90,7 +100,7 @@ nni_thr_wrap(void *arg) nni_plat_cv_wait(&thr->cv); } nni_plat_mtx_unlock(&thr->mtx); - if (!stop) { + if ((!stop) && (thr->fn != NULL)) { thr->fn(thr->arg); } nni_plat_mtx_lock(&thr->mtx); @@ -99,6 +109,7 @@ nni_thr_wrap(void *arg) nni_plat_mtx_unlock(&thr->mtx); } + int nni_thr_init(nni_thr *thr, nni_thr_func fn, void *arg) { @@ -125,6 +136,7 @@ nni_thr_init(nni_thr *thr, nni_thr_func fn, void *arg) return (0); } + void nni_thr_run(nni_thr *thr) { @@ -134,6 +146,7 @@ nni_thr_run(nni_thr *thr) nni_plat_mtx_unlock(&thr->mtx); } + void nni_thr_fini(nni_thr *thr) { @@ -147,4 +160,4 @@ nni_thr_fini(nni_thr *thr) nni_plat_thr_fini(&thr->thr); nni_plat_cv_fini(&thr->cv); nni_plat_mtx_fini(&thr->mtx); -} \ No newline at end of file +} -- cgit v1.2.3-70-g09d2