diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2019-09-13 05:05:25 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2019-09-13 05:05:25 +0000 |
commit | d72015c7962af72903326a01fb114f8f2d37eebc (patch) | |
tree | 5bb5ae6928f3f2a92f478f69c2f5c9aa9333fbf8 /libnetdata/threads/threads.c | |
parent | Releasing debian version 1.17.0-3. (diff) | |
download | netdata-d72015c7962af72903326a01fb114f8f2d37eebc.tar.xz netdata-d72015c7962af72903326a01fb114f8f2d37eebc.zip |
Merging upstream version 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.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/libnetdata/threads/threads.c b/libnetdata/threads/threads.c index 133d9a54..3b3f3041 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); |