summaryrefslogtreecommitdiffstats
path: root/libnetdata/threads/threads.c
diff options
context:
space:
mode:
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 5c3d2675..16de45fd 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);