Module: kamailio
Branch: 5.7
Commit: 0f1d78a22aeefef7601d0cf646ec154f5e52c175
URL:
https://github.com/kamailio/kamailio/commit/0f1d78a22aeefef7601d0cf646ec154…
Author: S-P Chan <shihping.chan(a)gmail.com>
Committer: S-P Chan <shihping.chan(a)gmail.com>
Date: 2024-02-27T05:11:08+08:00
core/rthreads.h: add thread executor for curl_global_init()
Cherry-pick from db05449932
---
Modified: src/core/rthreads.h
---
Diff:
https://github.com/kamailio/kamailio/commit/0f1d78a22aeefef7601d0cf646ec154…
Patch:
https://github.com/kamailio/kamailio/commit/0f1d78a22aeefef7601d0cf646ec154…
---
diff --git a/src/core/rthreads.h b/src/core/rthreads.h
index e96f45c9395..0f4f0cf8b8a 100644
--- a/src/core/rthreads.h
+++ b/src/core/rthreads.h
@@ -254,3 +254,41 @@ static int run_thread4P5I2P2(_thread_proto4P5I2P2 fn, void *arg1,
void *arg2,
#endif
}
#endif
+
+/*
+ * prototype: CURLcode curl_global_init(long flags) { ... }
+ */
+#ifdef KSR_RTHREAD_NEED_4L
+typedef int (*_thread_proto4L)(long);
+struct _thread_args4L
+{
+ _thread_proto4L fn;
+ long arg1;
+ int *ret;
+};
+static void *run_thread_wrap4L(struct _thread_args4L *args)
+{
+ *args->ret = (*args->fn)(args->arg1);
+ return NULL;
+}
+
+static int run_thread4L(_thread_proto4L fn, long arg1)
+{
+#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);
+ }
+ pthread_create(&tid, NULL, (_thread_proto)run_thread_wrap4L,
+ &(struct _thread_args4L){fn, arg1, &ret});
+ pthread_join(tid, NULL);
+
+ return ret;
+#else
+ return fn(arg1)
+#endif
+}
+#endif