diff --git a/daemon/helpers.c b/daemon/helpers.c index 3656604bf..73c2bab7f 100644 --- a/daemon/helpers.c +++ b/daemon/helpers.c @@ -263,36 +263,6 @@ static void *thread_detach_func(void *d) { return NULL; } -static int thread_create(void *(*func)(void *), void *arg, int joinable, pthread_t *handle, const char *name) { - pthread_attr_t att; - pthread_t thr; - int ret; - - if (pthread_attr_init(&att)) - abort(); - if (pthread_attr_setdetachstate(&att, joinable ? PTHREAD_CREATE_JOINABLE : PTHREAD_CREATE_DETACHED)) - abort(); - if (rtpe_config.common.thread_stack > 0) { - if (pthread_attr_setstacksize(&att, rtpe_config.common.thread_stack * 1024)) { - ilog(LOG_ERR, "Failed to set thread stack size to %llu", - (unsigned long long) rtpe_config.common.thread_stack * 1024); - abort(); - } - } - ret = pthread_create(&thr, &att, func, arg); - pthread_attr_destroy(&att); - if (ret) - return ret; - if (handle) - *handle = thr; -#ifdef __GLIBC__ - if (name) - pthread_setname_np(thr, name); -#endif - - return 0; -} - void thread_create_detach_prio(void (*f)(void *), void *d, const char *scheduler, int priority, const char *name) { @@ -304,7 +274,7 @@ void thread_create_detach_prio(void (*f)(void *), void *d, const char *scheduler dt->scheduler = scheduler; dt->priority = priority; - if (thread_create(thread_detach_func, dt, 1, NULL, name)) + if (thread_create(thread_detach_func, dt, true, NULL, name)) abort(); } diff --git a/lib/auxlib.c b/lib/auxlib.c index ac63c455c..e267dfd9c 100644 --- a/lib/auxlib.c +++ b/lib/auxlib.c @@ -70,6 +70,37 @@ void service_notify(const char *message) { } +int thread_create(void *(*func)(void *), void *arg, bool joinable, pthread_t *handle, const char *name) { + pthread_attr_t att; + pthread_t thr; + int ret; + + if (pthread_attr_init(&att)) + abort(); + if (pthread_attr_setdetachstate(&att, joinable ? PTHREAD_CREATE_JOINABLE : PTHREAD_CREATE_DETACHED)) + abort(); + if (rtpe_common_config_ptr->thread_stack > 0) { + if (pthread_attr_setstacksize(&att, rtpe_common_config_ptr->thread_stack * 1024)) { + ilog(LOG_ERR, "Failed to set thread stack size to %llu", + (unsigned long long) rtpe_common_config_ptr->thread_stack * 1024); + abort(); + } + } + ret = pthread_create(&thr, &att, func, arg); + pthread_attr_destroy(&att); + if (ret) + return ret; + if (handle) + *handle = thr; +#ifdef __GLIBC__ + if (name) + pthread_setname_np(thr, name); +#endif + + return 0; +} + + void resources(void) { struct rlimit rl; int tryv; diff --git a/lib/auxlib.h b/lib/auxlib.h index 851929376..b668eaea9 100644 --- a/lib/auxlib.h +++ b/lib/auxlib.h @@ -59,6 +59,7 @@ void config_load(int *argc, char ***argv, GOptionEntry *entries, const char *des struct rtpengine_common_config *); char *get_thread_buf(void); +int thread_create(void *(*func)(void *), void *arg, bool joinable, pthread_t *handle, const char *name); unsigned int in6_addr_hash(const void *p); int in6_addr_eq(const void *a, const void *b);