diff options
| author | Garrett D'Amore <garrett@damore.org> | 2020-08-08 18:25:48 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2020-08-08 19:30:17 -0700 |
| commit | 6c5070d9157ab0de667568655f0bbeb60780d701 (patch) | |
| tree | ab1a03e16907c97e6d76f1d95d79aea0f4a875ce /src/platform/posix/posix_thread.c | |
| parent | ddc0d044dd0fcf4aa1dc333fd5bda0de47850a64 (diff) | |
| download | nng-6c5070d9157ab0de667568655f0bbeb60780d701.tar.gz nng-6c5070d9157ab0de667568655f0bbeb60780d701.tar.bz2 nng-6c5070d9157ab0de667568655f0bbeb60780d701.zip | |
fixes #960 NNG threads inherit application thread name
This also exposes an nng_thread_set_name() function for
applications to use. All NNG thread names start with "nng:".
Note that support is highly dependent on the operating system.
Diffstat (limited to 'src/platform/posix/posix_thread.c')
| -rw-r--r-- | src/platform/posix/posix_thread.c | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/platform/posix/posix_thread.c b/src/platform/posix/posix_thread.c index b8fa814e..0178455f 100644 --- a/src/platform/posix/posix_thread.c +++ b/src/platform/posix/posix_thread.c @@ -1,5 +1,5 @@ // -// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a @@ -254,6 +254,31 @@ nni_plat_thr_is_self(nni_plat_thr *thr) } void +nni_plat_thr_set_name(nni_plat_thr *thr, const char *name) +{ +#if defined(NNG_HAVE_PTHREAD_SET_NAME_NP) + if (thr == NULL) { + pthread_set_name_np(pthread_self(), name); + } else { + pthread_set_name_np(thr->tid, name); + } +#elif defined(NNG_HAVE_PTHREAD_SETNAME_NP) +#if defined(__APPLE__) + // Darwin is weird, it can only set the name of pthread_self. + if ((thr == NULL) || (pthread_self() == thr->tid)) { + pthread_setname_np(name); + } +#else + if (thr == NULL) { + pthread_setname_np(pthread_self(), name); + } else { + pthread_setname_np(thr->tid, name); + } +#endif +#endif +} + +void nni_atfork_child(void) { nni_plat_forked = 1; |
