summaryrefslogtreecommitdiff
path: root/src/platform/posix/posix_thread.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/platform/posix/posix_thread.c')
-rw-r--r--src/platform/posix/posix_thread.c27
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;