Module: kamailio
Branch: master
Commit: aa15489f0a8de4a27197602d771fe02cf5745287
URL:
https://github.com/kamailio/kamailio/commit/aa15489f0a8de4a27197602d771fe02…
Author: S-P Chan <shihping.chan(a)gmail.com>
Committer: S-P Chan <shihping.chan(a)gmail.com>
Date: 2024-02-07T05:24:30+08:00
core/rthreads.h: use global ksr_tls_threads_mode to constrain thread
wrapping
- 0: run wrapped function directly
- 1: run wrapped function in thread for process#0 else run directly
- 2: always run wrapped function in thread
---
Modified: src/core/rthreads.h
---
Diff:
https://github.com/kamailio/kamailio/commit/aa15489f0a8de4a27197602d771fe02…
Patch:
https://github.com/kamailio/kamailio/commit/aa15489f0a8de4a27197602d771fe02…
---
diff --git a/src/core/rthreads.h b/src/core/rthreads.h
index a416ad2ca50..084f463261b 100644
--- a/src/core/rthreads.h
+++ b/src/core/rthreads.h
@@ -27,6 +27,7 @@
*/
#include <pthread.h>
+#include "./globals.h"
/*
* prototype: void *fn(void *arg) { ... }
*/
@@ -35,13 +36,21 @@ typedef void *(*_thread_proto)(void *);
#ifndef KSR_RTHREAD_SKIP_P
static void *run_threadP(_thread_proto fn, void *arg)
{
+#ifdef USE_TLS
pthread_t tid;
void *ret;
+ if(likely(ksr_tls_threads_mode == 0 || (ksr_tls_threads_mode == 1 &&
process_no > 0))) {
+ return fn(arg);
+ }
+
pthread_create(&tid, NULL, fn, arg);
pthread_join(tid, &ret);
return ret;
+#else
+ fn(arg);
+#endif /* USE_TLS */
}
#endif
@@ -63,14 +72,22 @@ static void *run_thread_wrapPI(struct _thread_argsPI *args)
static void *run_threadPI(_thread_protoPI fn, void *arg1, int arg2)
{
+#ifdef USE_TLS
pthread_t tid;
void *ret;
+ if(likely(ksr_tls_threads_mode == 0 || (ksr_tls_threads_mode == 1 &&
process_no > 0))) {
+ return fn(arg1, arg2);
+ }
+
pthread_create(&tid, NULL, (_thread_proto)&run_thread_wrapPI,
&(struct _thread_argsPI){fn, arg1, arg2});
pthread_join(tid, &ret);
return ret;
+#else
+ return fn(arg1, arg2);
+#endif
}
#endif
@@ -91,11 +108,19 @@ static void *run_thread_wrapV(struct _thread_argsV *args)
static void run_threadV(_thread_protoV fn)
{
+#ifdef USE_TLS
pthread_t tid;
+ if(likely(ksr_tls_threads_mode == 0 || (ksr_tls_threads_mode == 1 &&
process_no > 0))) {
+ fn();
+ }
+
pthread_create(&tid, NULL, (_thread_proto)run_thread_wrapV,
&(struct _thread_argsV){fn});
pthread_join(tid, NULL);
+#else
+ fn();
+#endif
}
#endif
@@ -119,14 +144,21 @@ static void *run_thread_wrap4PP(struct _thread_args4PP *args)
static int run_thread4PP(_thread_proto4PP fn, void *arg1, void *arg2)
{
+#ifdef USE_TLS
pthread_t tid;
int ret;
+ if(likely(ksr_tls_threads_mode == 0 || (ksr_tls_threads_mode == 1 &&
process_no > 0))) {
+ return fn(arg1, arg2);
+ }
pthread_create(&tid, NULL, (_thread_proto)run_thread_wrap4PP,
&(struct _thread_args4PP){fn, arg1, arg2, &ret});
pthread_join(tid, NULL);
return ret;
+#else
+ return fn(arg1, arg2);
+#endif
}
#endif
@@ -148,10 +180,17 @@ static void *run_thread_wrap0P(struct _thread_args0P *args)
static void run_thread0P(_thread_proto0P fn, void *arg1)
{
+#ifdef USE_TLS
pthread_t tid;
+ if(likely(ksr_tls_threads_mode == 0 || (ksr_tls_threads_mode == 1 &&
process_no > 0))) {
+ fn(arg1);
+ }
pthread_create(&tid, NULL, (_thread_proto)run_thread_wrap0P,
&(struct _thread_args0P){fn, arg1});
pthread_join(tid, NULL);
+#else
+ fn(arg1)
+#endif
}
#endif