From f452dd7ab4ac874eda65b73f31bcb08f221a520e Mon Sep 17 00:00:00 2001 From: Huang Qi Date: Fri, 18 Feb 2022 15:12:41 +0800 Subject: [PATCH] sched: Mark pthread as non-cancelable to avoid additional calls to pthread_exit() Signed-off-by: Huang Qi --- libs/libc/pthread/pthread_exit.c | 9 +++++++++ sched/pthread/pthread_exit.c | 11 ----------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/libs/libc/pthread/pthread_exit.c b/libs/libc/pthread/pthread_exit.c index fce8f3ef35c..c68ef6a7fac 100644 --- a/libs/libc/pthread/pthread_exit.c +++ b/libs/libc/pthread/pthread_exit.c @@ -54,6 +54,15 @@ void pthread_exit(FAR void *exit_value) { + /* Mark the pthread as non-cancelable to avoid additional calls to + * pthread_exit() due to any cancellation point logic that might get + * kicked off by actions taken during pthread_exit processing. + */ + +#ifdef CONFIG_CANCELLATION_POINTS + task_setcancelstate(TASK_CANCEL_DISABLE, NULL); +#endif + #ifdef CONFIG_PTHREAD_CLEANUP pthread_cleanup_popall(up_tls_info()); #endif diff --git a/sched/pthread/pthread_exit.c b/sched/pthread/pthread_exit.c index 8ef8ee7e6e4..22a7871e643 100644 --- a/sched/pthread/pthread_exit.c +++ b/sched/pthread/pthread_exit.c @@ -78,17 +78,6 @@ void nx_pthread_exit(FAR void *exit_value) nxsig_procmask(SIG_SETMASK, &set, NULL); -#ifdef CONFIG_CANCELLATION_POINTS - /* Mark the pthread as non-cancelable to avoid additional calls to - * pthread_exit() due to any cancellation point logic that might get - * kicked off by actions taken during pthread_exit processing. - */ - - tcb->flags |= TCB_FLAG_NONCANCELABLE; - tcb->flags &= ~TCB_FLAG_CANCEL_PENDING; - tcb->cpcount = 0; -#endif - /* Complete pending join operations */ status = pthread_completejoin(getpid(), exit_value);