summaryrefslogtreecommitdiffstats
path: root/libnetdata/threads/threads.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-02-06 16:11:30 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-02-06 16:11:30 +0000
commitaa2fe8ccbfcb117efa207d10229eeeac5d0f97c7 (patch)
tree941cbdd387b41c1a81587c20a6df9f0e5e0ff7ab /libnetdata/threads/threads.c
parentAdding upstream version 1.37.1. (diff)
downloadnetdata-aa2fe8ccbfcb117efa207d10229eeeac5d0f97c7.tar.xz
netdata-aa2fe8ccbfcb117efa207d10229eeeac5d0f97c7.zip
Adding upstream version 1.38.0.upstream/1.38.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'libnetdata/threads/threads.c')
-rw-r--r--libnetdata/threads/threads.c39
1 files changed, 21 insertions, 18 deletions
diff --git a/libnetdata/threads/threads.c b/libnetdata/threads/threads.c
index 5c3d2675c..16de45fd1 100644
--- a/libnetdata/threads/threads.c
+++ b/libnetdata/threads/threads.c
@@ -2,8 +2,7 @@
#include "../libnetdata.h"
-static size_t default_stacksize = 0, wanted_stacksize = 0;
-static pthread_attr_t *attr = NULL;
+static pthread_attr_t *netdata_threads_attr = NULL;
// ----------------------------------------------------------------------------
// per thread data
@@ -69,46 +68,48 @@ size_t netdata_threads_init(void) {
// --------------------------------------------------------------------
// get the required stack size of the threads of netdata
- attr = callocz(1, sizeof(pthread_attr_t));
- i = pthread_attr_init(attr);
+ netdata_threads_attr = callocz(1, sizeof(pthread_attr_t));
+ i = pthread_attr_init(netdata_threads_attr);
if(i != 0)
fatal("pthread_attr_init() failed with code %d.", i);
- i = pthread_attr_getstacksize(attr, &default_stacksize);
+ size_t stacksize = 0;
+ i = pthread_attr_getstacksize(netdata_threads_attr, &stacksize);
if(i != 0)
fatal("pthread_attr_getstacksize() failed with code %d.", i);
else
- debug(D_OPTIONS, "initial pthread stack size is %zu bytes", default_stacksize);
+ debug(D_OPTIONS, "initial pthread stack size is %zu bytes", stacksize);
- return default_stacksize;
+ return stacksize;
}
// ----------------------------------------------------------------------------
// late initialization
void netdata_threads_init_after_fork(size_t stacksize) {
- wanted_stacksize = stacksize;
int i;
// ------------------------------------------------------------------------
- // set default pthread stack size
+ // set pthread stack size
- if(attr && default_stacksize < wanted_stacksize && wanted_stacksize > 0) {
- i = pthread_attr_setstacksize(attr, wanted_stacksize);
+ if(netdata_threads_attr && stacksize > (size_t)PTHREAD_STACK_MIN) {
+ i = pthread_attr_setstacksize(netdata_threads_attr, stacksize);
if(i != 0)
- fatal("pthread_attr_setstacksize() to %zu bytes, failed with code %d.", wanted_stacksize, i);
+ error("pthread_attr_setstacksize() to %zu bytes, failed with code %d.", stacksize, i);
else
- debug(D_SYSTEM, "Successfully set pthread stacksize to %zu bytes", wanted_stacksize);
+ info("Set threads stack size to %zu bytes", stacksize);
}
+ else
+ error("Invalid pthread stacksize %zu", stacksize);
}
-
// ----------------------------------------------------------------------------
// netdata_thread_create
-extern void rrdset_thread_rda_free(void);
-extern void sender_thread_buffer_free(void);
-extern void query_target_free(void);
+void rrdset_thread_rda_free(void);
+void sender_thread_buffer_free(void);
+void query_target_free(void);
+void service_exits(void);
static void thread_cleanup(void *ptr) {
if(netdata_thread != ptr) {
@@ -123,6 +124,8 @@ static void thread_cleanup(void *ptr) {
rrdset_thread_rda_free();
query_target_free();
thread_cache_destroy();
+ service_exits();
+ worker_unregister();
freez((void *)netdata_thread->tag);
netdata_thread->tag = NULL;
@@ -214,7 +217,7 @@ int netdata_thread_create(netdata_thread_t *thread, const char *tag, NETDATA_THR
info->start_routine = start_routine;
info->options = options;
- int ret = pthread_create(thread, attr, thread_start, info);
+ int ret = pthread_create(thread, netdata_threads_attr, thread_start, info);
if(ret != 0)
error("failed to create new thread for %s. pthread_create() failed with code %d", tag, ret);