1 /*
2  * Copyright (c) 2006-2021, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2010-10-26     Bernard      the first version
9  */
10 
11 #ifndef __PTHREAD_INTERNAL_H__
12 #define __PTHREAD_INTERNAL_H__
13 
14 #include <rtthread.h>
15 #include <pthread.h>
16 #include <sys/time.h>
17 
18 struct _pthread_cleanup
19 {
20     void (*cleanup_func)(void *parameter);
21     void *parameter;
22 
23     struct _pthread_cleanup *next;
24 };
25 typedef struct _pthread_cleanup _pthread_cleanup_t;
26 
27 struct _pthread_key_data
28 {
29     int is_used;
30     void (*destructor)(void *parameter);
31 };
32 typedef struct _pthread_key_data _pthread_key_data_t;
33 
34 #ifndef PTHREAD_NUM_MAX
35 #define PTHREAD_NUM_MAX 32
36 #endif
37 
38 #define PTHREAD_MAGIC   0x70746873
39 struct _pthread_data
40 {
41     rt_uint32_t magic;
42     pthread_attr_t attr;
43     rt_thread_t tid;
44 
45     void* (*thread_entry)(void *parameter);
46     void *thread_parameter;
47 
48     /* return value */
49     void *return_value;
50 
51     /* semaphore for joinable thread */
52     rt_sem_t joinable_sem;
53 
54     /* cancel state and type */
55     rt_uint8_t cancelstate;
56     volatile rt_uint8_t canceltype;
57     volatile rt_uint8_t canceled;
58 
59     _pthread_cleanup_t *cleanup;
60     void** tls; /* thread-local storage area */
61 };
62 typedef struct _pthread_data _pthread_data_t;
63 
64 _pthread_data_t *_pthread_get_data(pthread_t thread);
65 
66 #endif
67