mirror of
https://github.com/apache/nuttx.git
synced 2026-06-07 01:05:54 +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:
+21
-2
@@ -558,6 +558,8 @@ void up_task_start(main_t taskentry, int argc, FAR char *argv[])
|
||||
noreturn_function;
|
||||
#endif
|
||||
|
||||
#if !defined(CONFIG_BUILD_FLAT) && defined(__KERNEL__) && \
|
||||
!defined(CONFIG_DISABLE_PTHREAD)
|
||||
/****************************************************************************
|
||||
* Name: up_pthread_start
|
||||
*
|
||||
@@ -583,11 +585,28 @@ void up_task_start(main_t taskentry, int argc, FAR char *argv[])
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if !defined(CONFIG_BUILD_FLAT) && defined(__KERNEL__) && \
|
||||
!defined(CONFIG_DISABLE_PTHREAD)
|
||||
void up_pthread_start(pthread_trampoline_t startup,
|
||||
pthread_startroutine_t entrypt, pthread_addr_t arg);
|
||||
noreturn_function;
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_pthread_exit
|
||||
*
|
||||
* Description:
|
||||
* In this kernel mode build, this function will be called to execute a
|
||||
* pthread in user-space. This kernel-mode stub will then be called
|
||||
* transfer control to the user-mode pthread_exit.
|
||||
*
|
||||
* Input Parameters:
|
||||
* exit - The user-space pthread_exit function
|
||||
* exit_value - The pointer of the pthread exit parameter
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
****************************************************************************/
|
||||
|
||||
void up_pthread_exit(pthread_exitroutine_t exit, FAR void *exit_value);
|
||||
noreturn_function;
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
@@ -140,6 +140,7 @@ EXTERN const pthread_attr_t g_default_pthread_attr;
|
||||
* for the new thread
|
||||
* entry - The new thread starts execution by invoking entry
|
||||
* arg - It is passed as the sole argument of entry
|
||||
* exit - The user-space pthread exit function
|
||||
*
|
||||
* Returned Value:
|
||||
* OK (0) on success; a (non-negated) errno value on failure. The errno
|
||||
@@ -149,7 +150,8 @@ EXTERN const pthread_attr_t g_default_pthread_attr;
|
||||
|
||||
int nx_pthread_create(pthread_trampoline_t trampoline, FAR pthread_t *thread,
|
||||
FAR const pthread_attr_t *attr,
|
||||
pthread_startroutine_t entry, pthread_addr_t arg);
|
||||
pthread_startroutine_t entry, pthread_addr_t arg,
|
||||
pthread_exitroutine_t exit);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nx_pthread_exit
|
||||
@@ -163,8 +165,6 @@ int nx_pthread_create(pthread_trampoline_t trampoline, FAR pthread_t *thread,
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
* Assumptions:
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void nx_pthread_exit(FAR void *exit_value) noreturn_function;
|
||||
|
||||
@@ -95,16 +95,17 @@
|
||||
#define TCB_FLAG_NONCANCELABLE (1 << 2) /* Bit 2: Pthread is non-cancelable */
|
||||
#define TCB_FLAG_CANCEL_DEFERRED (1 << 3) /* Bit 3: Deferred (vs asynch) cancellation type */
|
||||
#define TCB_FLAG_CANCEL_PENDING (1 << 4) /* Bit 4: Pthread cancel is pending */
|
||||
#define TCB_FLAG_POLICY_SHIFT (5) /* Bit 5-6: Scheduling policy */
|
||||
#define TCB_FLAG_CANCEL_DOING (1 << 5) /* Bit 4: Pthread cancel/exit is doing */
|
||||
#define TCB_FLAG_POLICY_SHIFT (6) /* Bit 5-6: Scheduling policy */
|
||||
#define TCB_FLAG_POLICY_MASK (3 << TCB_FLAG_POLICY_SHIFT)
|
||||
# define TCB_FLAG_SCHED_FIFO (0 << TCB_FLAG_POLICY_SHIFT) /* FIFO scheding policy */
|
||||
# define TCB_FLAG_SCHED_RR (1 << TCB_FLAG_POLICY_SHIFT) /* Round robin scheding policy */
|
||||
# define TCB_FLAG_SCHED_SPORADIC (2 << TCB_FLAG_POLICY_SHIFT) /* Sporadic scheding policy */
|
||||
# define TCB_FLAG_SCHED_OTHER (3 << TCB_FLAG_POLICY_SHIFT) /* Other scheding policy */
|
||||
#define TCB_FLAG_CPU_LOCKED (1 << 7) /* Bit 7: Locked to this CPU */
|
||||
#define TCB_FLAG_SIGNAL_ACTION (1 << 8) /* Bit 8: In a signal handler */
|
||||
#define TCB_FLAG_SYSCALL (1 << 9) /* Bit 9: In a system call */
|
||||
#define TCB_FLAG_EXIT_PROCESSING (1 << 10) /* Bit 10: Exitting */
|
||||
#define TCB_FLAG_CPU_LOCKED (1 << 8) /* Bit 7: Locked to this CPU */
|
||||
#define TCB_FLAG_SIGNAL_ACTION (1 << 9) /* Bit 8: In a signal handler */
|
||||
#define TCB_FLAG_SYSCALL (1 << 10) /* Bit 9: In a system call */
|
||||
#define TCB_FLAG_EXIT_PROCESSING (1 << 11) /* Bit 10: Exitting */
|
||||
/* Bits 11-15: Available */
|
||||
|
||||
/* Values for struct task_group tg_flags */
|
||||
@@ -761,6 +762,7 @@ struct pthread_tcb_s
|
||||
|
||||
pthread_trampoline_t trampoline; /* User-space pthread startup function */
|
||||
pthread_addr_t arg; /* Startup argument */
|
||||
pthread_exitroutine_t exit; /* User-space pthread exit function */
|
||||
FAR void *joininfo; /* Detach-able info to support join */
|
||||
};
|
||||
#endif /* !CONFIG_DISABLE_PTHREAD */
|
||||
|
||||
@@ -225,6 +225,8 @@ typedef FAR void *pthread_addr_t;
|
||||
typedef CODE pthread_addr_t (*pthread_startroutine_t)(pthread_addr_t);
|
||||
typedef pthread_startroutine_t pthread_func_t;
|
||||
|
||||
typedef void (*pthread_exitroutine_t)(pthread_addr_t);
|
||||
|
||||
typedef void (*pthread_trampoline_t)(pthread_startroutine_t, pthread_addr_t);
|
||||
|
||||
struct pthread_attr_s
|
||||
|
||||
@@ -305,7 +305,7 @@ SYSCALL_LOOKUP(telldir, 1)
|
||||
SYSCALL_LOOKUP(pthread_cond_broadcast, 1)
|
||||
SYSCALL_LOOKUP(pthread_cond_signal, 1)
|
||||
SYSCALL_LOOKUP(pthread_cond_wait, 2)
|
||||
SYSCALL_LOOKUP(nx_pthread_create, 5)
|
||||
SYSCALL_LOOKUP(nx_pthread_create, 6)
|
||||
SYSCALL_LOOKUP(pthread_detach, 1)
|
||||
SYSCALL_LOOKUP(nx_pthread_exit, 1)
|
||||
SYSCALL_LOOKUP(pthread_getschedparam, 3)
|
||||
|
||||
Reference in New Issue
Block a user