diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-11-30 18:47:05 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-11-30 18:47:05 +0000 |
commit | 97e01009d69b8fbebfebf68f51e3d126d0ed43fc (patch) | |
tree | 02e8b836c3a9d89806f3e67d4a5fe9f52dbb0061 /libnetdata/threads/threads.c | |
parent | Releasing debian version 1.36.1-1. (diff) | |
download | netdata-97e01009d69b8fbebfebf68f51e3d126d0ed43fc.tar.xz netdata-97e01009d69b8fbebfebf68f51e3d126d0ed43fc.zip |
Merging upstream version 1.37.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | libnetdata/threads/threads.c | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/libnetdata/threads/threads.c b/libnetdata/threads/threads.c index 12007afff..5c3d2675c 100644 --- a/libnetdata/threads/threads.c +++ b/libnetdata/threads/threads.c @@ -29,26 +29,35 @@ const char *netdata_thread_tag(void) { // ---------------------------------------------------------------------------- // compatibility library functions +static __thread pid_t gettid_cached_tid = 0; pid_t gettid(void) { + pid_t tid = 0; + + if(likely(gettid_cached_tid > 0)) + return gettid_cached_tid; + #ifdef __FreeBSD__ - return (pid_t)pthread_getthreadid_np(); + tid = (pid_t)pthread_getthreadid_np(); #elif defined(__APPLE__) #if (defined __MAC_OS_X_VERSION_MIN_REQUIRED && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1060) uint64_t curthreadid; pthread_threadid_np(NULL, &curthreadid); - return (pid_t)curthreadid; + tid = (pid_t)curthreadid; #else /* __MAC_OS_X_VERSION_MIN_REQUIRED */ - return (pid_t)pthread_self; + tid = (pid_t)pthread_self; #endif /* __MAC_OS_X_VERSION_MIN_REQUIRED */ #else /* __APPLE__*/ - return (pid_t)syscall(SYS_gettid); + tid = (pid_t)syscall(SYS_gettid); #endif /* __FreeBSD__, __APPLE__*/ + + gettid_cached_tid = tid; + return tid; } // ---------------------------------------------------------------------------- @@ -97,6 +106,10 @@ void netdata_threads_init_after_fork(size_t stacksize) { // ---------------------------------------------------------------------------- // netdata_thread_create +extern void rrdset_thread_rda_free(void); +extern void sender_thread_buffer_free(void); +extern void query_target_free(void); + static void thread_cleanup(void *ptr) { if(netdata_thread != ptr) { NETDATA_THREAD *info = (NETDATA_THREAD *)ptr; @@ -106,6 +119,11 @@ static void thread_cleanup(void *ptr) { if(!(netdata_thread->options & NETDATA_THREAD_OPTION_DONT_LOG_CLEANUP)) info("thread with task id %d finished", gettid()); + sender_thread_buffer_free(); + rrdset_thread_rda_free(); + query_target_free(); + thread_cache_destroy(); + freez((void *)netdata_thread->tag); netdata_thread->tag = NULL; @@ -213,11 +231,18 @@ int netdata_thread_create(netdata_thread_t *thread, const char *tag, NETDATA_THR // ---------------------------------------------------------------------------- // netdata_thread_cancel - +#ifdef NETDATA_INTERNAL_CHECKS +int netdata_thread_cancel_with_trace(netdata_thread_t thread, int line, const char *file, const char *function) { +#else int netdata_thread_cancel(netdata_thread_t thread) { +#endif int ret = pthread_cancel(thread); if(ret != 0) +#ifdef NETDATA_INTERNAL_CHECKS + error("cannot cancel thread. pthread_cancel() failed with code %d at %d@%s, function %s()", ret, line, file, function); +#else error("cannot cancel thread. pthread_cancel() failed with code %d.", ret); +#endif return ret; } |