1 /* 2 * Copyright (C) 2015-2021 Alibaba Group Holding Limited 3 */ 4 5 #ifndef __POSIX_INTERNAL_PTHREAD_H 6 #define __POSIX_INTERNAL_PTHREAD_H 7 8 #include <pthread.h> 9 #include <aos/kernel.h> 10 11 #define PTHREAD_DEFAULT_STACK_SIZE 2048 12 #define PTHREAD_DEFAULT_GUARD_SIZE 256 13 #define PTHREAD_DEFAULT_PRIORITY 30 14 #define PTHREAD_DEFAULT_SLICE 10 15 #define PTHREAD_NAME_MAX_LEN 16 16 17 #define PTHREAD_TCB_MAGIC 0X11223344 18 19 #define DEFAULT_MUTEX_TYPE PTHREAD_MUTEX_DEFAULT 20 #define DEFAULT_MUTEX_PROCOCOL PTHREAD_PRIO_INHERIT 21 #define DEFAULT_MUTEX_PRIOCEILING 30 22 #define DEFAULT_MUTEX_PSHARED PTHREAD_PROCESS_PRIVATE 23 24 #define DEFAULT_COND_CLOCK CLOCK_REALTIME 25 #define DEFAULT_COND_SHARED PTHREAD_PROCESS_PRIVATE 26 27 28 typedef struct pthread_cleanup { 29 int cancel_type; 30 struct pthread_cleanup *prev; 31 void (*cleanup_routine)(void *para); 32 void *para; 33 } pthread_cleanup_t; 34 35 typedef struct pthread_tcb { 36 aos_task_t task; /* The rhino task handle. */ 37 unsigned int magic; /* The pthread tcb memory magic number. */ 38 void *(*thread_entry)(void *para); /* The start routine of the thread. */ 39 void *thread_para; /* The parameter of start routine. */ 40 aos_sem_t join_sem; /* The semaphore for pthread_join. */ 41 pthread_cleanup_t *cleanup; /* The registered cleanup function for the thread.*/ 42 void *environ; 43 void **tls; 44 void *return_value; /* The thread's return value. */ 45 pthread_attr_t attr; /* The thread's attribute. */ 46 char thread_name[PTHREAD_NAME_MAX_LEN + 1]; /* The thread's name. */ 47 } pthread_tcb_t; 48 __pthread_get_tcb(pthread_t thread)49static inline pthread_tcb_t* __pthread_get_tcb(pthread_t thread) 50 { 51 pthread_tcb_t* ptcb = (pthread_tcb_t*)thread; 52 53 if ((ptcb == NULL) || (ptcb->magic != PTHREAD_TCB_MAGIC)) { 54 return NULL; 55 } 56 57 return ptcb; 58 } 59 60 void pthread_tsd_dtors(void); 61 62 #endif /* __POSIX_INTERNAL_PTHREAD_H */ 63