diff options
Diffstat (limited to 'src/platform/posix')
| -rw-r--r-- | src/platform/posix/posix_impl.h | 1 | ||||
| -rw-r--r-- | src/platform/posix/posix_thread.c | 9 |
2 files changed, 10 insertions, 0 deletions
diff --git a/src/platform/posix/posix_impl.h b/src/platform/posix/posix_impl.h index 1ab728c5..3faebfd4 100644 --- a/src/platform/posix/posix_impl.h +++ b/src/platform/posix/posix_impl.h @@ -60,6 +60,7 @@ extern int nni_plat_devnull; // open descriptor on /dev/null // elsewhere. struct nni_plat_mtx { + int init; pthread_mutex_t mtx; }; diff --git a/src/platform/posix/posix_thread.c b/src/platform/posix/posix_thread.c index 91fbdff7..113dd9ea 100644 --- a/src/platform/posix/posix_thread.c +++ b/src/platform/posix/posix_thread.c @@ -50,6 +50,7 @@ nni_plat_mtx_init(nni_plat_mtx *mtx) nni_panic("pthread_mutex_init: %s", strerror(rv)); } } + mtx->init = 1; return (0); } @@ -59,9 +60,13 @@ nni_plat_mtx_fini(nni_plat_mtx *mtx) { int rv; + if (!mtx->init) { + return; + } if ((rv = pthread_mutex_destroy(&mtx->mtx)) != 0) { nni_panic("pthread_mutex_fini: %s", strerror(rv)); } + mtx->init = 0; } @@ -159,9 +164,13 @@ nni_plat_cv_fini(nni_plat_cv *cv) { int rv; + if (cv->mtx == NULL) { + return; + } if ((rv = pthread_cond_destroy(&cv->cv)) != 0) { nni_panic("pthread_cond_destroy: %s", strerror(rv)); } + cv->mtx = NULL; } |
