diff options
| author | Garrett D'Amore <garrett@damore.org> | 2016-12-22 02:19:18 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2016-12-22 02:19:18 -0800 |
| commit | 6c1325a2b17548a4249d26a846bc32b95b7d747d (patch) | |
| tree | cecb3df7477d99a0380c5959a4e2f5afe5d03b5e /src/platform/posix/posix_thread.c | |
| parent | 101c1b6a946d9f2f48c6dd89940ae669141e0511 (diff) | |
| download | nng-6c1325a2b17548a4249d26a846bc32b95b7d747d.tar.gz nng-6c1325a2b17548a4249d26a846bc32b95b7d747d.tar.bz2 nng-6c1325a2b17548a4249d26a846bc32b95b7d747d.zip | |
Start of work to inline mutexes and condition variables.
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); } |
