From b8099f1bdffeea76718ecb8ea3766850e641b795 Mon Sep 17 00:00:00 2001 From: hmilylmk Date: Fri, 26 Aug 2022 11:03:57 +0800 Subject: [PATCH] dsoftbus: fix set pthread stack size failed * In glibc, pthread_attr_setstacksize will return failed when passing stacksize that less than PTHREAD_STACK_MIN macro. This macro value is 128k in aarch64 and 16k in other archs, which defines in pthread_stack_min.h file. * pthread_attr_setstacksize has different implementation in different libc. Open harmony using musl-libc, which don't have this limit below. While openeuler embedded using glibc, so using __GLIBC__ macro to fix it. Signed-off-by: hmilylmk --- core/common/message_handler/message_handler.c | 8 ++++++++ core/connection/common/src/softbus_thread_pool.c | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/core/common/message_handler/message_handler.c b/core/common/message_handler/message_handler.c index 50216565..ee6ee214 100644 --- a/core/common/message_handler/message_handler.c +++ b/core/common/message_handler/message_handler.c @@ -190,11 +190,19 @@ static void *LoopTask(void *arg) static int StartNewLooperThread(SoftBusLooper *looper) { +#ifdef __GLIBC__ +#ifdef __aarch64__ +#define MAINLOOP_STACK_SIZE 131072 +#else +#define MAINLOOP_STACK_SIZE 16384 +#endif // __aarch64__ +#else // not glibc #ifdef ASAN_BUILD #define MAINLOOP_STACK_SIZE 10240 #else #define MAINLOOP_STACK_SIZE 8192 #endif +#endif // __GLIBC__ int ret; SoftBusThreadAttr threadAttr; SoftBusThread tid; diff --git a/core/connection/common/src/softbus_thread_pool.c b/core/connection/common/src/softbus_thread_pool.c index 9f6c9f0c..badc32b5 100755 --- a/core/connection/common/src/softbus_thread_pool.c +++ b/core/connection/common/src/softbus_thread_pool.c @@ -24,7 +24,15 @@ #include "softbus_log.h" #ifndef MIN_STACK_SIZE +#ifdef __GLIBC__ +#ifdef __aarch64__ +#define MIN_STACK_SIZE 0x20000 +#else +#define MIN_STACK_SIZE 0x4000 +#endif // __aarch64__ +#else // not glibc #define MIN_STACK_SIZE 0x8000 +#endif // __GLIBC__ #endif #define THREAD_POOL_NAME "THREAD_POOL" -- Gitee