summaryrefslogtreecommitdiffstats
path: root/libnetdata/threads/threads.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2019-09-13 05:05:16 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2019-09-13 05:05:16 +0000
commit8f5d8f3de6cae180af37917ef978a4affc2cd464 (patch)
tree4bfe1abc6d19c2dd635d1b83cc0e73d0aa6904ac /libnetdata/threads/threads.c
parentAdding upstream version 1.17.0. (diff)
downloadnetdata-8f5d8f3de6cae180af37917ef978a4affc2cd464.tar.xz
netdata-8f5d8f3de6cae180af37917ef978a4affc2cd464.zip
Adding upstream version 1.17.1.upstream/1.17.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'libnetdata/threads/threads.c')
-rw-r--r--libnetdata/threads/threads.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/libnetdata/threads/threads.c b/libnetdata/threads/threads.c
index 133d9a547..3b3f30415 100644
--- a/libnetdata/threads/threads.c
+++ b/libnetdata/threads/threads.c
@@ -109,6 +109,31 @@ static void thread_cleanup(void *ptr) {
netdata_thread = NULL;
}
+static void thread_set_name(NETDATA_THREAD *nt) {
+
+ if (nt->tag) {
+ int ret = 0;
+
+ // Name is limited to 16 chars
+ char threadname[16];
+ strncpyz(threadname, nt->tag, 15);
+
+#if defined(__FreeBSD__)
+ pthread_set_name_np(pthread_self(), threadname);
+#elif defined(__APPLE__)
+ ret = pthread_setname_np(threadname);
+#else
+ ret = pthread_setname_np(pthread_self(), threadname);
+#endif
+
+ if (ret != 0)
+ error("cannot set pthread name of %d to %s. ErrCode: %d", gettid(), threadname, ret);
+ else
+ info("set name of thread %d to %s", gettid(), threadname);
+
+ }
+}
+
static void *thread_start(void *ptr) {
netdata_thread = (NETDATA_THREAD *)ptr;
@@ -121,6 +146,8 @@ static void *thread_start(void *ptr) {
if(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0)
error("cannot set pthread cancel state to ENABLE.");
+ thread_set_name(ptr);
+
void *ret = NULL;
pthread_cleanup_push(thread_cleanup, ptr);
ret = netdata_thread->start_routine(netdata_thread->arg);