diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-01-16 16:27:22 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-01-16 16:27:22 -0800 |
| commit | ac8415c24ffea645105c3859e814843e81c97f8a (patch) | |
| tree | 7b64b4aab3de6ce5bdd69c3d5b7ead57f4a4b4e7 /src/core/thread.c | |
| parent | b8f7236aa2928d70d9bff2e1071654982539eeda (diff) | |
| download | nng-ac8415c24ffea645105c3859e814843e81c97f8a.tar.gz nng-ac8415c24ffea645105c3859e814843e81c97f8a.tar.bz2 nng-ac8415c24ffea645105c3859e814843e81c97f8a.zip | |
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.
Diffstat (limited to 'src/core/thread.c')
| -rw-r--r-- | src/core/thread.c | 9 |
1 files changed, 9 insertions, 0 deletions
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); } |
