diff options
Diffstat (limited to 'src/platform/posix/posix_thread.c')
| -rw-r--r-- | src/platform/posix/posix_thread.c | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/src/platform/posix/posix_thread.c b/src/platform/posix/posix_thread.c index 8928974c..1bbe6e28 100644 --- a/src/platform/posix/posix_thread.c +++ b/src/platform/posix/posix_thread.c @@ -71,12 +71,15 @@ nni_thread_reap(nni_thread_t thr) void -atfork_child(void) +nni_atfork_child(void) { plat_fork = 1; } +pthread_condattr_t nni_condattr; +pthread_mutexattr_t nni_mutexattr; + int nni_plat_init(int (*helper)(void)) { @@ -93,7 +96,30 @@ nni_plat_init(int (*helper)(void)) pthread_mutex_unlock(&plat_lock); return (0); } - if (pthread_atfork(NULL, NULL, atfork_child) != 0) { + if (pthread_condattr_init(&nni_condattr) != 0) { + pthread_mutex_unlock(&plat_lock); + return (NNG_ENOMEM); + } +#if !defined(NNG_USE_GETTIMEOFDAY) && NNG_USE_CLOCKID != CLOCK_REALTIME + if (pthread_condattr_setclock(&nni_condattr, NNG_USE_CLOCKID) != 0) { + pthread_mutex_unlock(&plat_lock); + return (NNG_ENOMEM); + } +#endif + + if (pthread_mutexattr_init(&nni_mutexattr) != 0) { + pthread_mutex_unlock(&plat_lock); + return (NNG_ENOMEM); + } + + if (pthread_mutexattr_settype(&nni_mutexattr, + PTHREAD_MUTEX_ERRORCHECK) != 0) { + pthread_mutex_unlock(&plat_lock); + return (NNG_ENOMEM); + } + + + if (pthread_atfork(NULL, NULL, nni_atfork_child) != 0) { pthread_mutex_unlock(&plat_lock); return (NNG_ENOMEM); } @@ -109,7 +135,13 @@ nni_plat_init(int (*helper)(void)) void nni_plat_fini(void) { - // XXX: NOTHING *YET* + pthread_mutex_lock(&plat_lock); + if (plat_init) { + pthread_mutexattr_destroy(&nni_mutexattr); + pthread_condattr_destroy(&nni_condattr); + plat_init = 0; + } + pthread_mutex_unlock(&plat_lock); } |
