task/pthread_cancelpt: Move cancel point handling to libc, data to TLS

This moves task / thread cancel point logic from the NuttX kernel into
libc, while the data needed by the cancel point logic is moved to TLS.

The change is an enabler to move user-space APIs to libc as well, for
a coherent user/kernel separation.
This commit is contained in:
Ville Juven
2023-11-10 12:56:10 +02:00
committed by Xiang Xiao
parent 1e31ec8003
commit 0dedbcd4ae
24 changed files with 414 additions and 547 deletions
+8
View File
@@ -58,6 +58,14 @@
#include <stdbool.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define CANCEL_FLAG_NONCANCELABLE (1 << 0) /* Pthread is non-cancelable */
#define CANCEL_FLAG_CANCEL_ASYNC (1 << 1) /* Async (vs deferred) cancellation type */
#define CANCEL_FLAG_CANCEL_PENDING (1 << 2) /* Pthread cancel is pending */
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
+10 -15
View File
@@ -89,22 +89,20 @@
# define TCB_FLAG_TTYPE_TASK (0 << TCB_FLAG_TTYPE_SHIFT) /* Normal user task */
# define TCB_FLAG_TTYPE_PTHREAD (1 << TCB_FLAG_TTYPE_SHIFT) /* User pthread */
# define TCB_FLAG_TTYPE_KERNEL (2 << TCB_FLAG_TTYPE_SHIFT) /* Kernel thread */
#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_POLICY_SHIFT (3) /* Bit 3-4: 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_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 */
#define TCB_FLAG_FREE_STACK (1 << 12) /* Bit 12: Free stack after exit */
#define TCB_FLAG_HEAP_CHECK (1 << 13) /* Bit 13: Heap check */
#define TCB_FLAG_HEAP_DUMP (1 << 14) /* Bit 14: Heap dump */
#define TCB_FLAG_DETACHED (1 << 15) /* Bit 15: Pthread detached */
#define TCB_FLAG_CPU_LOCKED (1 << 5) /* Bit 5: Locked to this CPU */
#define TCB_FLAG_SIGNAL_ACTION (1 << 6) /* Bit 6: In a signal handler */
#define TCB_FLAG_SYSCALL (1 << 7) /* Bit 7: In a system call */
#define TCB_FLAG_EXIT_PROCESSING (1 << 8) /* Bit 8: Exitting */
#define TCB_FLAG_FREE_STACK (1 << 9) /* Bit 9: Free stack after exit */
#define TCB_FLAG_HEAP_CHECK (1 << 10) /* Bit 10: Heap check */
#define TCB_FLAG_HEAP_DUMP (1 << 11) /* Bit 11: Heap dump */
#define TCB_FLAG_DETACHED (1 << 12) /* Bit 12: Pthread detached */
#define TCB_FLAG_FORCED_CANCEL (1 << 13) /* Bit 13: Pthread cancel is forced */
/* Values for struct task_group tg_flags */
@@ -572,9 +570,6 @@ struct tcb_s
int16_t lockcount; /* 0=preemptible (not-locked) */
#ifdef CONFIG_IRQCOUNT
int16_t irqcount; /* 0=Not in critical section */
#endif
#ifdef CONFIG_CANCELLATION_POINTS
int16_t cpcount; /* Nested cancellation point count */
#endif
int16_t errcode; /* Used to pass error information */
+26 -1
View File
@@ -206,6 +206,12 @@ struct tls_info_s
struct pthread_cleanup_s tl_stack[CONFIG_PTHREAD_CLEANUP_STACKSIZE];
#endif
uint8_t tl_cpstate; /* Cancellation state */
#ifdef CONFIG_CANCELLATION_POINTS
int16_t tl_cpcount; /* Nested cancellation point count */
#endif
int tl_errno; /* Per-thread error number */
};
@@ -310,9 +316,28 @@ uintptr_t task_tls_get_value(int tlsindex);
#elif defined(CONFIG_TLS_ALIGNED) && !defined(__KERNEL__)
# define tls_get_info() TLS_INFO(up_getsp())
#else
FAR struct tls_info_s *tls_get_info(void);
# define tls_get_info() tls_get_info_pid(0)
#endif
/****************************************************************************
* Name: tls_get_info_pid
*
* Description:
* Return a reference to the tls_info_s structure. This is used as part
* of the internal implementation of tls_get/set_elem() and ONLY for the
* where CONFIG_TLS_ALIGNED is *not* defined or __KERNEL__ is defined.
*
* Input Parameters:
* pid - Thread ID to query, set to 0 to query own
*
* Returned Value:
* A reference to the thread-specific tls_info_s structure is return on
* success. NULL would be returned in the event of any failure.
*
****************************************************************************/
FAR struct tls_info_s *tls_get_info_pid(pid_t pid);
/****************************************************************************
* Name: tls_destruct
*
-7
View File
@@ -105,13 +105,6 @@ SYSCALL_LOOKUP(sem_wait, 1)
SYSCALL_LOOKUP(pgalloc, 2)
#endif
SYSCALL_LOOKUP(task_setcancelstate, 2)
#ifdef CONFIG_CANCELLATION_POINTS
SYSCALL_LOOKUP(task_setcanceltype, 2)
SYSCALL_LOOKUP(task_testcancel, 0)
#endif
/* The following can be individually enabled */
#ifdef CONFIG_ARCH_HAVE_FORK