diff --git a/include/nuttx/pthread.h b/include/nuttx/pthread.h index 3170586aa9c..a9ebf508aa7 100644 --- a/include/nuttx/pthread.h +++ b/include/nuttx/pthread.h @@ -176,7 +176,7 @@ void nx_pthread_exit(FAR void *exit_value) noreturn_function; * within the pthread_exit() and pthread_cancellation() logic * * Input Parameters: - * None + * tls - The local storage info of the exiting thread * * Returned Value: * None @@ -184,7 +184,7 @@ void nx_pthread_exit(FAR void *exit_value) noreturn_function; ****************************************************************************/ #ifdef CONFIG_PTHREAD_CLEANUP -void pthread_cleanup_popall(void); +void pthread_cleanup_popall(FAR struct tls_info_s *tls); #endif #undef EXTERN diff --git a/libs/libc/pthread/pthread_cleanup.c b/libs/libc/pthread/pthread_cleanup.c index 8d4ba7f5aad..6aabcb4a7c1 100644 --- a/libs/libc/pthread/pthread_cleanup.c +++ b/libs/libc/pthread/pthread_cleanup.c @@ -172,17 +172,15 @@ void pthread_cleanup_push(pthread_cleanup_t routine, FAR void *arg) * within the pthread_exit() and pthread_cancellation() logic * * Input Parameters: - * None + * tls - The local storage info of the exiting thread * * Returned Value: * None * ****************************************************************************/ -void pthread_cleanup_popall(void) +void pthread_cleanup_popall(FAR struct tls_info_s *tls) { - FAR struct tls_info_s *tls = up_tls_info(); - DEBUGASSERT(tls != NULL); sched_lock(); diff --git a/libs/libc/pthread/pthread_exit.c b/libs/libc/pthread/pthread_exit.c index 22d684eaf22..fce8f3ef35c 100644 --- a/libs/libc/pthread/pthread_exit.c +++ b/libs/libc/pthread/pthread_exit.c @@ -28,6 +28,7 @@ #include #include +#include #include #include @@ -54,7 +55,7 @@ void pthread_exit(FAR void *exit_value) { #ifdef CONFIG_PTHREAD_CLEANUP - pthread_cleanup_popall(); + pthread_cleanup_popall(up_tls_info()); #endif #if CONFIG_TLS_NELEM > 0 diff --git a/sched/pthread/pthread_cancel.c b/sched/pthread/pthread_cancel.c index 1a4ef237e09..469847ae17c 100644 --- a/sched/pthread/pthread_cancel.c +++ b/sched/pthread/pthread_cancel.c @@ -30,6 +30,9 @@ #include #include +#include +#include + #include "sched/sched.h" #include "task/task.h" #include "pthread/pthread.h" @@ -86,6 +89,12 @@ int pthread_cancel(pthread_t thread) pthread_exit(PTHREAD_CANCELED); } + /* Refer to up_tls_info() */ + +#ifdef CONFIG_PTHREAD_CLEANUP + pthread_cleanup_popall(tcb->stack_alloc_ptr); +#endif + /* Complete pending join operations */ pthread_completejoin((pid_t)thread, PTHREAD_CANCELED);