From bc7a6f22f23e95aad3ecd42adf9ac2b7b75a47e1 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sat, 7 Jan 2017 21:49:48 -0800 Subject: Simplify locking for protocols. In an attempt to simplify the protocol implementation, and hopefully track down a close related race, we've made it so that most protocols need not worry about locks, and can access the socket lock if they do need a lock. They also let the socket manage their workers, for the most part. (The req protocol is special, since it needs a top level work distributor, *and* a resender.) --- src/core/thread.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/core/thread.c') diff --git a/src/core/thread.c b/src/core/thread.c index 7678ad0a..4a871ede 100644 --- a/src/core/thread.c +++ b/src/core/thread.c @@ -128,6 +128,10 @@ nni_thr_init(nni_thr *thr, nni_thr_func fn, void *arg) nni_plat_mtx_fini(&thr->mtx); return (rv); } + if (fn == NULL) { + thr->done = 1; + return (0); + } if ((rv = nni_plat_thr_init(&thr->thr, nni_thr_wrap, thr)) != 0) { nni_plat_cv_fini(&thr->cv); nni_plat_mtx_fini(&thr->mtx); @@ -170,7 +174,9 @@ nni_thr_fini(nni_thr *thr) nni_plat_cv_wait(&thr->cv); } nni_plat_mtx_unlock(&thr->mtx); - nni_plat_thr_fini(&thr->thr); + if (thr->fn != NULL) { + nni_plat_thr_fini(&thr->thr); + } nni_plat_cv_fini(&thr->cv); nni_plat_mtx_fini(&thr->mtx); } -- cgit v1.2.3-70-g09d2