xref: /nrf52832-nimble/rt-thread/components/libc/pthreads/pthread_internal.h (revision 104654410c56c573564690304ae786df310c91fc)
1 /*
2  * Copyright (c) 2006-2018, 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 
17 struct _pthread_cleanup
18 {
19     void (*cleanup_func)(void *parameter);
20     void *parameter;
21 
22     struct _pthread_cleanup *next;
23 };
24 typedef struct _pthread_cleanup _pthread_cleanup_t;
25 
26 struct _pthread_key_data
27 {
28     int is_used;
29     void (*destructor)(void *parameter);
30 };
31 typedef struct _pthread_key_data _pthread_key_data_t;
32 
33 #define PTHREAD_MAGIC   0x70746873
34 struct _pthread_data
35 {
36     rt_uint32_t magic;
37     pthread_attr_t attr;
38     rt_thread_t tid;
39 
40     void* (*thread_entry)(void *parameter);
41     void *thread_parameter;
42 
43     /* return value */
44     void *return_value;
45 
46     /* semaphore for joinable thread */
47     rt_sem_t joinable_sem;
48 
49     /* cancel state and type */
50     rt_uint8_t cancelstate;
51     volatile rt_uint8_t canceltype;
52     volatile rt_uint8_t canceled;
53 
54     _pthread_cleanup_t *cleanup;
55     void** tls; /* thread-local storage area */
56 };
57 typedef struct _pthread_data _pthread_data_t;
58 
_pthread_get_data(pthread_t thread)59 rt_inline _pthread_data_t *_pthread_get_data(pthread_t thread)
60 {
61     _pthread_data_t *ptd;
62     RT_ASSERT(thread != RT_NULL);
63 
64     ptd = (_pthread_data_t *)thread->user_data;
65     RT_ASSERT(ptd != RT_NULL);
66     RT_ASSERT(ptd->magic == PTHREAD_MAGIC);
67 
68     return ptd;
69 }
70 
71 int clock_time_to_tick(const struct timespec *time);
72 
73 void posix_mq_system_init(void);
74 void posix_sem_system_init(void);
75 void pthread_key_system_init(void);
76 
77 #endif
78