mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 08:36:24 +08:00
libc: Call pthread_exit in user-space by up_pthread_exit
Drop to user-space in kernel/protected build with up_pthread_exit, now all pthread_cleanup functions executed in user mode. * A new syscall SYS_pthread_exit added * A new tcb flag TCB_FLAG_CANCEL_DOING added * up_pthread_exit implemented for riscv/arm arch Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
This commit is contained in:
@@ -57,6 +57,7 @@
|
||||
|
||||
#include <nuttx/irq.h>
|
||||
#include <nuttx/cancelpt.h>
|
||||
#include <nuttx/pthread.h>
|
||||
|
||||
#include "sched/sched.h"
|
||||
#include "semaphore/semaphore.h"
|
||||
@@ -139,7 +140,15 @@ bool enter_cancellation_point(void)
|
||||
if ((tcb->flags & TCB_FLAG_TTYPE_MASK) ==
|
||||
TCB_FLAG_TTYPE_PTHREAD)
|
||||
{
|
||||
#if !defined(CONFIG_BUILD_FLAT) && defined(__KERNEL__)
|
||||
tcb->flags &= ~TCB_FLAG_CANCEL_PENDING;
|
||||
tcb->flags |= TCB_FLAG_CANCEL_DOING;
|
||||
|
||||
up_pthread_exit(((FAR struct pthread_tcb_s *)tcb)->exit,
|
||||
PTHREAD_CANCELED);
|
||||
#else
|
||||
pthread_exit(PTHREAD_CANCELED);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
#endif
|
||||
@@ -226,7 +235,15 @@ void leave_cancellation_point(void)
|
||||
if ((tcb->flags & TCB_FLAG_TTYPE_MASK) ==
|
||||
TCB_FLAG_TTYPE_PTHREAD)
|
||||
{
|
||||
#if !defined(CONFIG_BUILD_FLAT) && defined(__KERNEL__)
|
||||
tcb->flags &= ~TCB_FLAG_CANCEL_PENDING;
|
||||
tcb->flags |= TCB_FLAG_CANCEL_DOING;
|
||||
|
||||
up_pthread_exit(((FAR struct pthread_tcb_s *)tcb)->exit,
|
||||
PTHREAD_CANCELED);
|
||||
#else
|
||||
pthread_exit(PTHREAD_CANCELED);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
#endif
|
||||
|
||||
@@ -112,7 +112,15 @@ int task_setcancelstate(int state, FAR int *oldstate)
|
||||
if ((tcb->flags & TCB_FLAG_TTYPE_MASK) ==
|
||||
TCB_FLAG_TTYPE_PTHREAD)
|
||||
{
|
||||
#if !defined(CONFIG_BUILD_FLAT) && defined(__KERNEL__)
|
||||
tcb->flags &= ~TCB_FLAG_CANCEL_PENDING;
|
||||
tcb->flags |= TCB_FLAG_CANCEL_DOING;
|
||||
|
||||
up_pthread_exit(((FAR struct pthread_tcb_s *)tcb)->exit,
|
||||
PTHREAD_CANCELED);
|
||||
#else
|
||||
pthread_exit(PTHREAD_CANCELED);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
#endif
|
||||
|
||||
@@ -100,7 +100,15 @@ int task_setcanceltype(int type, FAR int *oldtype)
|
||||
#ifndef CONFIG_DISABLE_PTHREAD
|
||||
if ((tcb->flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_PTHREAD)
|
||||
{
|
||||
pthread_exit(PTHREAD_CANCELED);
|
||||
#if !defined(CONFIG_BUILD_FLAT) && defined(__KERNEL__)
|
||||
tcb->flags &= ~TCB_FLAG_CANCEL_PENDING;
|
||||
tcb->flags |= TCB_FLAG_CANCEL_DOING;
|
||||
|
||||
up_pthread_exit(((FAR struct pthread_tcb_s *)tcb)->exit,
|
||||
PTHREAD_CANCELED);
|
||||
#else
|
||||
pthread_exit(PTHREAD_CANCELED);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user