• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef _PTHREAD_H
2 #define _PTHREAD_H
3 #ifdef __cplusplus
4 extern "C" {
5 #endif
6 
7 #include <features.h>
8 #include <sys/types.h>
9 #include <sched.h>
10 #include <time.h>
11 #include "los_task_pri.h"
12 #include "los_mux_pri.h"
13 
14 #define __NEED_time_t
15 #define __NEED_clockid_t
16 #define __NEED_struct_timespec
17 #define __NEED_struct_cpu_set_t
18 #define __NEED_struct_sched_param
19 #define __NEED_sigset_t
20 #define __NEED_pthread_t
21 #define __NEED_pthread_attr_t
22 #define __NEED_pthread_mutexattr_t
23 #define __NEED_pthread_condattr_t
24 
25 #define __NEED_pthread_key_t
26 #define __NEED_pthread_once_t
27 #define __NEED_size_t
28 #define __NEED_locale_t
29 
30 #include <bits/alltypes.h>
31 
32 #define __NEED_pthread_mutex_t
33 #define __NEED_pthread_cond_t
34 
35 #ifndef POSIX_MUTEX_DEFAULT_INHERIT
36 #define POSIX_MUTEX_DEFAULT_INHERIT 1
37 #endif
38 
39 #if defined(__NEED_pthread_mutexattr_t) && !defined(__DEFINED_pthread_mutexattr_t)
40 typedef LosMuxAttr pthread_mutexattr_t;
41 #define __DEFINED_pthread_mutexattr_t
42 #endif
43 
44 #if defined(__NEED_pthread_mutex_t) && !defined(__DEFINED_pthread_mutex_t)
45 typedef LosMux pthread_mutex_t;
46 #define pthread_mutex OsMux
47 #define __DEFINED_pthread_mutex_t
48 #endif
49 
50 #if defined(__NEED_pthread_cond_t) && !defined(__DEFINED_pthread_cond_t)
51 typedef struct pthread_cond {
52   volatile int count;      /**< The number of tasks blocked by condition */
53   EVENT_CB_S event;        /**< Event object*/
54   pthread_mutex_t* mutex;  /**< Mutex locker for condition variable protection */
55   volatile int value;      /**< Condition variable state value*/
56 } pthread_cond_t;
57 #define __DEFINED_pthread_cond_t
58 #endif
59 
60 #define PTHREAD_CREATE_JOINABLE 0
61 #define PTHREAD_CREATE_DETACHED 1
62 
63 #define PTHREAD_MUTEX_NORMAL LOS_MUX_NORMAL
64 #define PTHREAD_MUTEX_DEFAULT PTHREAD_MUTEX_NORMAL
65 #define PTHREAD_MUTEX_RECURSIVE LOS_MUX_RECURSIVE
66 #define PTHREAD_MUTEX_ERRORCHECK LOS_MUX_ERRORCHECK
67 
68 #define PTHREAD_MUTEX_ERRORCHECK_NP PTHREAD_MUTEX_ERRORCHECK
69 #define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE
70 
71 #define PTHREAD_MUTEX_STALLED 0
72 #define PTHREAD_MUTEX_ROBUST 1
73 
74 #define PTHREAD_PRIO_NONE    LOS_MUX_PRIO_NONE
75 #define PTHREAD_PRIO_INHERIT LOS_MUX_PRIO_INHERIT
76 #define PTHREAD_PRIO_PROTECT LOS_MUX_PRIO_PROTECT
77 
78 #define PTHREAD_INHERIT_SCHED 0
79 #define PTHREAD_EXPLICIT_SCHED 1
80 
81 #define PTHREAD_SCOPE_SYSTEM 0
82 #define PTHREAD_SCOPE_PROCESS 1
83 
84 #define PTHREAD_PROCESS_PRIVATE 0
85 #define PTHREAD_PROCESS_SHARED 1
86 
87 #ifndef POSIX_MUTEX_DEFAULT_INHERIT
88 #define POSIX_MUTEX_DEFAULT_INHERIT
89 #endif
90 #if defined POSIX_MUTEX_DEFAULT_INHERIT
91 
92 #define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \
93     { OS_MUX_MAGIC, { PTHREAD_PRIO_INHERIT, OS_TASK_PRIORITY_LOWEST, PTHREAD_MUTEX_RECURSIVE_NP, 0 }, \
94      { (struct LOS_DL_LIST *)NULL, (struct LOS_DL_LIST *)NULL }, \
95      { (struct LOS_DL_LIST *)NULL, (struct LOS_DL_LIST *)NULL }, \
96      (VOID *)NULL, 0 }
97 
98 #define PTHREAD_MUTEX_INITIALIZER \
99     { OS_MUX_MAGIC, { PTHREAD_PRIO_INHERIT, OS_TASK_PRIORITY_LOWEST, 0, 0 }, \
100      { (struct LOS_DL_LIST *)NULL, (struct LOS_DL_LIST *)NULL }, \
101      { (struct LOS_DL_LIST *)NULL, (struct LOS_DL_LIST *)NULL }, \
102      (VOID *)NULL, 0 }
103 #elif defined POSIX_MUTEX_DEFAULT_PROTECT
104 
105 #define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \
106     { OS_MUX_MAGIC, { PTHREAD_PRIO_PROTECT, OS_TASK_PRIORITY_LOWEST, PTHREAD_MUTEX_RECURSIVE_NP, 0 }, \
107      { (struct LOS_DL_LIST *)NULL, (struct LOS_DL_LIST *)NULL }, \
108      { (struct LOS_DL_LIST *)NULL, (struct LOS_DL_LIST *)NULL }, \
109      (VOID *)NULL, 0 }
110 
111 #define PTHREAD_MUTEX_INITIALIZER \
112     { OS_MUX_MAGIC, { PTHREAD_PRIO_PROTECT, OS_TASK_PRIORITY_LOWEST, 0, 0 },  \
113      { (struct LOS_DL_LIST *)NULL, (struct LOS_DL_LIST *)NULL }, \
114      { (struct LOS_DL_LIST *)NULL, (struct LOS_DL_LIST *)NULL }, \
115      (VOID *)NULL, 0 }
116 #else
117 
118 #define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \
119     { OS_MUX_MAGIC, { PTHREAD_PRIO_NONE, OS_TASK_PRIORITY_LOWEST, PTHREAD_MUTEX_RECURSIVE_NP, 0 }, \
120      { (struct LOS_DL_LIST *)NULL, (struct LOS_DL_LIST *)NULL }, \
121      { (struct LOS_DL_LIST *)NULL, (struct LOS_DL_LIST *)NULL }, \
122      (VOID *)NULL, 0 }
123 
124 #define PTHREAD_MUTEX_INITIALIZER \
125     { OS_MUX_MAGIC, { PTHREAD_PRIO_NONE, OS_TASK_PRIORITY_LOWEST, 0, 0 }, \
126      { (struct LOS_DL_LIST *)NULL, (struct LOS_DL_LIST *)NULL }, \
127      { (struct LOS_DL_LIST *)NULL, (struct LOS_DL_LIST *)NULL }, \
128      (VOID *)NULL, 0 }
129 #endif
130 #define PTHREAD_RWLOCK_INITIALIZER {0}
131 #define PTHREAD_COND_INITIALIZER { -1, { 0, { NULL, NULL } } , NULL, -1 }
132 #define PTHREAD_ONCE_INIT 0
133 
134 
135 #define PTHREAD_CANCEL_ENABLE 0
136 #define PTHREAD_CANCEL_DISABLE 1
137 #define PTHREAD_CANCEL_MASKED 2
138 
139 #define PTHREAD_CANCEL_DEFERRED 0
140 #define PTHREAD_CANCEL_ASYNCHRONOUS 1
141 
142 #define PTHREAD_CANCELED ((void *)-1)
143 
144 
145 #define PTHREAD_BARRIER_SERIAL_THREAD (-1)
146 
147 
148 int pthread_create(pthread_t *__restrict, const pthread_attr_t *__restrict, void *(*)(void *), void *__restrict);
149 int pthread_detach(pthread_t);
150 void pthread_exit(void *);
151 int pthread_join(pthread_t, void **);
152 
153 #ifdef __GNUC__
154 __attribute__((const))
155 #endif
156 pthread_t pthread_self(void);
157 
158 int pthread_equal(pthread_t, pthread_t);
159 
160 int pthread_setcancelstate(int, int *);
161 int pthread_setcanceltype(int, int *);
162 void pthread_testcancel(void);
163 int pthread_cancel(pthread_t);
164 
165 int pthread_getschedparam(pthread_t, int *__restrict, struct sched_param *__restrict);
166 int pthread_setschedparam(pthread_t, int, const struct sched_param *);
167 int pthread_setschedprio(pthread_t, int);
168 
169 int pthread_once(pthread_once_t *, void (*)(void));
170 
171 int pthread_mutex_init(pthread_mutex_t *__restrict, const pthread_mutexattr_t *__restrict);
172 int pthread_mutex_lock(pthread_mutex_t *);
173 int pthread_mutex_unlock(pthread_mutex_t *);
174 int pthread_mutex_trylock(pthread_mutex_t *);
175 int pthread_mutex_timedlock(pthread_mutex_t *__restrict, const struct timespec *__restrict);
176 int pthread_mutex_destroy(pthread_mutex_t *);
177 int pthread_mutex_consistent(pthread_mutex_t *);
178 
179 int pthread_mutex_getprioceiling(const pthread_mutex_t *__restrict, int *__restrict);
180 int pthread_mutex_setprioceiling(pthread_mutex_t *__restrict, int, int *__restrict);
181 
182 int pthread_cond_init(pthread_cond_t *__restrict, const pthread_condattr_t *__restrict);
183 int pthread_cond_destroy(pthread_cond_t *);
184 int pthread_cond_wait(pthread_cond_t *__restrict, pthread_mutex_t *__restrict);
185 int pthread_cond_timedwait(pthread_cond_t *__restrict, pthread_mutex_t *__restrict, const struct timespec *__restrict);
186 int pthread_cond_broadcast(pthread_cond_t *);
187 int pthread_cond_signal(pthread_cond_t *);
188 
189 int pthread_key_create(pthread_key_t *, void (*)(void *));
190 int pthread_key_delete(pthread_key_t);
191 void *pthread_getspecific(pthread_key_t);
192 int pthread_setspecific(pthread_key_t, const void *);
193 
194 int pthread_attr_init(pthread_attr_t *);
195 int pthread_attr_destroy(pthread_attr_t *);
196 
197 int pthread_attr_getguardsize(const pthread_attr_t *__restrict, size_t *__restrict);
198 int pthread_attr_setguardsize(pthread_attr_t *, size_t);
199 int pthread_attr_getstacksize(const pthread_attr_t *__restrict, size_t *__restrict);
200 int pthread_attr_setstacksize(pthread_attr_t *, size_t);
201 int pthread_attr_getdetachstate(const pthread_attr_t *, int *);
202 int pthread_attr_setdetachstate(pthread_attr_t *, int);
203 int pthread_attr_getstack(const pthread_attr_t *__restrict, void **__restrict, size_t *__restrict);
204 int pthread_attr_setstack(pthread_attr_t *, void *, size_t);
205 int pthread_attr_getscope(const pthread_attr_t *__restrict, int *__restrict);
206 int pthread_attr_setscope(pthread_attr_t *, int);
207 int pthread_attr_getschedpolicy(const pthread_attr_t *__restrict, int *__restrict);
208 int pthread_attr_setschedpolicy(pthread_attr_t *, int);
209 int pthread_attr_getschedparam(const pthread_attr_t *__restrict, struct sched_param *__restrict);
210 int pthread_attr_setschedparam(pthread_attr_t *__restrict, const struct sched_param *__restrict);
211 int pthread_attr_getinheritsched(const pthread_attr_t *__restrict, int *__restrict);
212 int pthread_attr_setinheritsched(pthread_attr_t *, int);
213 
214 int pthread_attr_setstackaddr(pthread_attr_t *, void *);
215 int pthread_attr_getstackaddr(const pthread_attr_t *, void **);
216 
217 int pthread_mutexattr_destroy(pthread_mutexattr_t *);
218 int pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *__restrict, int *__restrict);
219 int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *__restrict, int *__restrict);
220 int pthread_mutexattr_getpshared(const pthread_mutexattr_t *__restrict, int *__restrict);
221 int pthread_mutexattr_getrobust(const pthread_mutexattr_t *__restrict, int *__restrict);
222 int pthread_mutexattr_gettype(const pthread_mutexattr_t *__restrict, int *__restrict);
223 int pthread_mutexattr_init(pthread_mutexattr_t *);
224 int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *, int);
225 int pthread_mutexattr_setprotocol(pthread_mutexattr_t *, int);
226 int pthread_mutexattr_setpshared(pthread_mutexattr_t *, int);
227 int pthread_mutexattr_setrobust(pthread_mutexattr_t *, int);
228 int pthread_mutexattr_settype(pthread_mutexattr_t *, int);
229 
230 int pthread_condattr_init(pthread_condattr_t *);
231 int pthread_condattr_destroy(pthread_condattr_t *);
232 int pthread_condattr_setclock(pthread_condattr_t *, clockid_t);
233 int pthread_condattr_setpshared(pthread_condattr_t *, int);
234 int pthread_condattr_getclock(const pthread_condattr_t *__restrict, clockid_t *__restrict);
235 int pthread_condattr_getpshared(const pthread_condattr_t *__restrict, int *__restrict);
236 
237 int pthread_atfork(void (*)(void), void (*)(void), void (*)(void));
238 
239 int pthread_getconcurrency(void);
240 int pthread_setconcurrency(int);
241 
242 int pthread_getcpuclockid(pthread_t, clockid_t *);
243 
244 struct pthread_cleanup_buffer {
245   struct pthread_cleanup_buffer *prev;  /**< Pointer to the buffer to be cleaned*/
246   void (*routine)(void *);               /**< General execution function*/
247   void *arg;                            /**< Parameter of the execution function*/
248 };
249 
250 void pthread_cleanup_push_inner(struct pthread_cleanup_buffer *, void (*)(void *), void *);
251 void pthread_cleanup_pop_inner(struct pthread_cleanup_buffer *, int);
252 
253 #define pthread_cleanup_push(f, x)  \
254 {   \
255   struct pthread_cleanup_buffer _buffer_; \
256   pthread_cleanup_push_inner(&_buffer_, (f), (x));
257 
258 #define pthread_cleanup_pop(r)  \
259   pthread_cleanup_pop_inner(&_buffer_, (r)); \
260 }
261 
262 #ifdef _GNU_SOURCE
263 struct cpu_set_t;
264 int pthread_attr_setaffinity_np(pthread_attr_t *, size_t, const cpu_set_t *);
265 int pthread_attr_getaffinity_np(const pthread_attr_t *, size_t, cpu_set_t *);
266 int pthread_getaffinity_np(pthread_t, size_t, struct cpu_set_t *);
267 int pthread_setaffinity_np(pthread_t, size_t, const struct cpu_set_t *);
268 int pthread_getattr_np(pthread_t, pthread_attr_t *);
269 int pthread_setname_np(pthread_t, const char *);
270 int pthread_getattr_default_np(pthread_attr_t *);
271 int pthread_setattr_default_np(const pthread_attr_t *);
272 int pthread_tryjoin_np(pthread_t, void **);
273 int pthread_timedjoin_np(pthread_t, void **, const struct timespec *);
274 #endif
275 
276 #if _REDIR_TIME64
277 __REDIR(pthread_mutex_timedlock, __pthread_mutex_timedlock_time64);
278 __REDIR(pthread_cond_timedwait, __pthread_cond_timedwait_time64);
279 __REDIR(pthread_rwlock_timedrdlock, __pthread_rwlock_timedrdlock_time64);
280 __REDIR(pthread_rwlock_timedwrlock, __pthread_rwlock_timedwrlock_time64);
281 #ifdef _GNU_SOURCE
282 __REDIR(pthread_timedjoin_np, __pthread_timedjoin_np_time64);
283 #endif
284 #endif
285 
286 #ifdef __cplusplus
287 }
288 #endif
289 #endif
290