From ac8415c24ffea645105c3859e814843e81c97f8a Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Mon, 16 Jan 2017 16:27:22 -0800 Subject: Start of event framework. This compiles correctly, but doesn't actually deliver events yet. As part of this, I've made most of the initializables in nng safe to tear-down if uninitialized (or set to zero e.g. via calloc). This makes it loads easier to write the teardown on error code, since I can deinit everything, without worrying about which things have been initialized and which have not. --- src/core/thread.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/core/thread.c') diff --git a/src/core/thread.c b/src/core/thread.c index 50d63521..91bacdec 100644 --- a/src/core/thread.c +++ b/src/core/thread.c @@ -115,21 +115,26 @@ nni_thr_init(nni_thr *thr, nni_thr_func fn, void *arg) thr->arg = arg; if ((rv = nni_plat_mtx_init(&thr->mtx)) != 0) { + thr->done = 1; return (rv); } if ((rv = nni_plat_cv_init(&thr->cv, &thr->mtx)) != 0) { nni_plat_mtx_fini(&thr->mtx); + thr->done = 1; return (rv); } if (fn == NULL) { + thr->init = 1; thr->done = 1; return (0); } if ((rv = nni_plat_thr_init(&thr->thr, nni_thr_wrap, thr)) != 0) { + thr->done = 1; nni_plat_cv_fini(&thr->cv); nni_plat_mtx_fini(&thr->mtx); return (rv); } + thr->init = 1; return (0); } @@ -160,6 +165,9 @@ nni_thr_wait(nni_thr *thr) void nni_thr_fini(nni_thr *thr) { + if (!thr->init) { + return; + } nni_plat_mtx_lock(&thr->mtx); thr->stop = 1; nni_plat_cv_wake(&thr->cv); @@ -170,6 +178,7 @@ nni_thr_fini(nni_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