mirror of
https://github.com/apache/nuttx.git
synced 2026-06-08 01:42:58 +08:00
pthreads: Add pthread_cleanup_push() and pthread_cleanup_pop()
This commit is contained in:
@@ -322,6 +322,18 @@ struct child_status_s
|
||||
};
|
||||
#endif
|
||||
|
||||
/* struct pthread_cleanup_s ******************************************************/
|
||||
|
||||
#ifdef CONFIG_PTHREAD_CLEANUP
|
||||
/* This structure describes one element of the pthread cleanup stack */
|
||||
|
||||
struct pthread_cleanup_s
|
||||
{
|
||||
pthread_cleanup_t pc_cleaner; /* Cleanup callback address */
|
||||
FAR void *pc_arg; /* Argument that accompanies the callback */
|
||||
};
|
||||
#endif
|
||||
|
||||
/* struct dspace_s ***************************************************************/
|
||||
/* This structure describes a reference counted D-Space region. This must be a
|
||||
* separately allocated "break-away" structure that can be owned by a task and
|
||||
@@ -682,6 +694,17 @@ struct pthread_tcb_s
|
||||
pthread_addr_t arg; /* Startup argument */
|
||||
FAR void *joininfo; /* Detach-able info to support join */
|
||||
|
||||
/* Clean-up stack *************************************************************/
|
||||
|
||||
#ifdef CONFIG_PTHREAD_CLEANUP
|
||||
/* tos - The index to the next avaiable entry at the top of the stack.
|
||||
* stack - The pre-allocated clean-up stack memory.
|
||||
*/
|
||||
|
||||
uint8_t tos;
|
||||
struct pthread_cleanup_s stack[CONFIG_PTHREAD_CLEANUP_STACKSIZE];
|
||||
#endif
|
||||
|
||||
/* POSIX Thread Specific Data *************************************************/
|
||||
|
||||
#if CONFIG_NPTHREAD_KEYS > 0
|
||||
|
||||
@@ -265,6 +265,12 @@ typedef struct pthread_barrier_s pthread_barrier_t;
|
||||
typedef bool pthread_once_t;
|
||||
#define __PTHREAD_ONCE_T_DEFINED 1
|
||||
|
||||
#ifdef CONFIG_PTHREAD_CLEANUP
|
||||
/* This type describes the pthread cleanup callback (non-standard) */
|
||||
|
||||
typedef CODE void (*pthread_cleanup_t)(FAR void *arg);
|
||||
#endif
|
||||
|
||||
/* Forward references */
|
||||
|
||||
struct sched_param; /* Defined in sched.h */
|
||||
@@ -336,6 +342,15 @@ int pthread_cancel(pthread_t thread);
|
||||
int pthread_setcancelstate(int state, FAR int *oldstate);
|
||||
void pthread_testcancel(void);
|
||||
|
||||
/* A thread may set up cleanup functions to execut when the thread exits or
|
||||
* is canceled.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_PTHREAD_CLEANUP
|
||||
void pthread_cleanup_pop(int execute);
|
||||
void pthread_cleanup_push(pthread_cleanup_t routine, FAR void *arg);
|
||||
#endif
|
||||
|
||||
/* A thread can await termination of another thread and retrieve the return
|
||||
* value of the thread.
|
||||
*/
|
||||
|
||||
+11
-3
@@ -406,7 +406,7 @@
|
||||
# define SYS_pthread_setspecific (__SYS_pthread+26)
|
||||
# define SYS_pthread_yield (__SYS_pthread+27)
|
||||
|
||||
# ifndef CONFIG_SMP
|
||||
# ifdef CONFIG_SMP
|
||||
# define SYS_pthread_setaffinity_np (__SYS_pthread+28)
|
||||
# define SYS_pthread_getaffinity_np (__SYS_pthread+29)
|
||||
# define __SYS_pthread_signals (__SYS_pthread+30)
|
||||
@@ -418,9 +418,17 @@
|
||||
# define SYS_pthread_cond_timedwait (__SYS_pthread_signals+0)
|
||||
# define SYS_pthread_kill (__SYS_pthread_signals+1)
|
||||
# define SYS_pthread_sigmask (__SYS_pthread_signals+2)
|
||||
# define __SYS_mqueue (__SYS_pthread_signals+3)
|
||||
# define __SYS_pthread_cleanup (__SYS_pthread_signals+3)
|
||||
# else
|
||||
# define __SYS_mqueue __SYS_pthread_signals
|
||||
# define __SYS_pthread_cleanup __SYS_pthread_signals
|
||||
# endif
|
||||
|
||||
# ifdef CONFIG_PTHREAD_CLEANUP
|
||||
# define __SYS_pthread_cleanup_push (__SYS_pthread_cleanup+0)
|
||||
# define __SYS_pthread_cleanup_pop (__SYS_pthread_cleanup+1)
|
||||
# define __SYS_mqueue (__SYS_pthread_cleanup+2)
|
||||
# else
|
||||
# define __SYS_mqueue __SYS_pthread_cleanup
|
||||
# endif
|
||||
|
||||
#else
|
||||
|
||||
Reference in New Issue
Block a user