1 | /* pthread.h |
---|
2 | * |
---|
3 | * $Id$ |
---|
4 | */ |
---|
5 | |
---|
6 | #ifndef __PTHREAD_h |
---|
7 | #define __PTHREAD_h |
---|
8 | |
---|
9 | #include <sys/features.h> |
---|
10 | |
---|
11 | #if defined(_POSIX_THREADS) |
---|
12 | |
---|
13 | #include <sys/types.h> |
---|
14 | #include <time.h> |
---|
15 | #include <sys/sched.h> |
---|
16 | |
---|
17 | /* |
---|
18 | * 3.1.3 Register Fork Handlers, P1003.1c/Draft 10, P1003.1c/Draft 10, p. 27 |
---|
19 | * |
---|
20 | * RTEMS does not support processes, so we fall under this and do not |
---|
21 | * provide this routine: |
---|
22 | * |
---|
23 | * "Either the implementation shall support the pthread_atfork() function |
---|
24 | * as described above or the pthread_atfork() funciton shall not be |
---|
25 | * provided." |
---|
26 | */ |
---|
27 | |
---|
28 | /* |
---|
29 | * 11.3.1 Mutex Initialization Attributes, P1003.1c/Draft 10, p. 81 |
---|
30 | */ |
---|
31 | |
---|
32 | int pthread_mutexattr_init( |
---|
33 | pthread_mutexattr_t *attr |
---|
34 | ); |
---|
35 | |
---|
36 | int pthread_mutexattr_destroy( |
---|
37 | pthread_mutexattr_t *attr |
---|
38 | ); |
---|
39 | |
---|
40 | int pthread_mutexattr_getpshared( |
---|
41 | const pthread_mutexattr_t *attr, |
---|
42 | int *pshared |
---|
43 | ); |
---|
44 | |
---|
45 | int pthread_mutexattr_setpshared( |
---|
46 | pthread_mutexattr_t *attr, |
---|
47 | int pshared |
---|
48 | ); |
---|
49 | |
---|
50 | /* |
---|
51 | * 11.3.2 Initializing and Destroying a Mutex, P1003.1c/Draft 10, p. 87 |
---|
52 | */ |
---|
53 | |
---|
54 | int pthread_mutex_init( |
---|
55 | pthread_mutex_t *mutex, |
---|
56 | const pthread_mutexattr_t *attr |
---|
57 | ); |
---|
58 | |
---|
59 | int pthread_mutex_destroy( |
---|
60 | pthread_mutex_t *mutex |
---|
61 | ); |
---|
62 | |
---|
63 | /* |
---|
64 | * This is used to statically initialize a pthread_mutex_t. Example: |
---|
65 | * |
---|
66 | * pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; |
---|
67 | */ |
---|
68 | |
---|
69 | #define PTHREAD_MUTEX_INITIALIZER ((pthread_mutex_t) 0xFFFFFFFF) |
---|
70 | |
---|
71 | /* |
---|
72 | * 11.3.3 Locking and Unlocking a Mutex, P1003.1c/Draft 10, p. 93 |
---|
73 | * |
---|
74 | * NOTE: P1003.4b/D8 adds pthread_mutex_timedlock(), p. 29 |
---|
75 | */ |
---|
76 | |
---|
77 | int pthread_mutex_lock( |
---|
78 | pthread_mutex_t *mutex |
---|
79 | ); |
---|
80 | |
---|
81 | int pthread_mutex_trylock( |
---|
82 | pthread_mutex_t *mutex |
---|
83 | ); |
---|
84 | |
---|
85 | int pthread_mutex_unlock( |
---|
86 | pthread_mutex_t *mutex |
---|
87 | ); |
---|
88 | |
---|
89 | #if defined(_POSIX_TIMEOUTS) |
---|
90 | |
---|
91 | int pthread_mutex_timedlock( |
---|
92 | pthread_mutex_t *mutex, |
---|
93 | const struct timespec *timeout |
---|
94 | ); |
---|
95 | |
---|
96 | #endif /* _POSIX_TIMEOUTS */ |
---|
97 | |
---|
98 | /* |
---|
99 | * 11.4.1 Condition Variable Initialization Attributes, |
---|
100 | * P1003.1c/Draft 10, p. 96 |
---|
101 | */ |
---|
102 | |
---|
103 | int pthread_condattr_init( |
---|
104 | pthread_condattr_t *attr |
---|
105 | ); |
---|
106 | |
---|
107 | int pthread_condattr_destroy( |
---|
108 | pthread_condattr_t *attr |
---|
109 | ); |
---|
110 | |
---|
111 | int pthread_condattr_getpshared( |
---|
112 | const pthread_condattr_t *attr, |
---|
113 | int *pshared |
---|
114 | ); |
---|
115 | |
---|
116 | int pthread_condattr_setpshared( |
---|
117 | pthread_condattr_t *attr, |
---|
118 | int pshared |
---|
119 | ); |
---|
120 | |
---|
121 | /* |
---|
122 | * 11.4.2 Initializing and Destroying a Condition Variable, |
---|
123 | * P1003.1c/Draft 10, p. 87 |
---|
124 | */ |
---|
125 | |
---|
126 | int pthread_cond_init( |
---|
127 | pthread_cond_t *cond, |
---|
128 | const pthread_condattr_t *attr |
---|
129 | ); |
---|
130 | |
---|
131 | int pthread_cond_destroy( |
---|
132 | pthread_cond_t *mutex |
---|
133 | ); |
---|
134 | |
---|
135 | /* |
---|
136 | * This is used to statically initialize a pthread_cond_t. Example: |
---|
137 | * |
---|
138 | * pthread_cond_t cond = PTHREAD_COND_INITIALIZER; |
---|
139 | */ |
---|
140 | |
---|
141 | #define PTHREAD_COND_INITIALIZER ((pthread_mutex_t) 0xFFFFFFFF) |
---|
142 | |
---|
143 | /* |
---|
144 | * 11.4.3 Broadcasting and Signaling a Condition, P1003.1c/Draft 10, p. 101 |
---|
145 | */ |
---|
146 | |
---|
147 | int pthread_cond_signal( |
---|
148 | pthread_cond_t *cond |
---|
149 | ); |
---|
150 | |
---|
151 | int pthread_cond_broadcast( |
---|
152 | pthread_cond_t *cond |
---|
153 | ); |
---|
154 | |
---|
155 | /* |
---|
156 | * 11.4.4 Waiting on a Condition, P1003.1c/Draft 10, p. 105 |
---|
157 | */ |
---|
158 | |
---|
159 | int pthread_cond_wait( |
---|
160 | pthread_cond_t *cond, |
---|
161 | pthread_mutex_t *mutex |
---|
162 | ); |
---|
163 | |
---|
164 | int pthread_cond_timedwait( |
---|
165 | pthread_cond_t *cond, |
---|
166 | pthread_mutex_t *mutex, |
---|
167 | const struct timespec *abstime |
---|
168 | ); |
---|
169 | |
---|
170 | #if defined(_POSIX_THREAD_PRIORITY_SCHEDULING) |
---|
171 | |
---|
172 | /* |
---|
173 | * 13.5.1 Thread Creation Scheduling Attributes, P1003.1c/Draft 10, p. 120 |
---|
174 | */ |
---|
175 | |
---|
176 | int pthread_attr_setscope( |
---|
177 | pthread_attr_t *attr, |
---|
178 | int contentionscope |
---|
179 | ); |
---|
180 | |
---|
181 | int pthread_attr_getscope( |
---|
182 | const pthread_attr_t *attr, |
---|
183 | int *contentionscope |
---|
184 | ); |
---|
185 | |
---|
186 | #define PTHREAD_INHERIT_SCHED 1 /* scheduling policy and associated */ |
---|
187 | /* attributes are inherited from */ |
---|
188 | /* the calling thread. */ |
---|
189 | #define PTHREAD_EXPLICIT_SCHED 2 /* set from provided attribute object */ |
---|
190 | |
---|
191 | int pthread_attr_setinheritsched( |
---|
192 | pthread_attr_t *attr, |
---|
193 | int inheritsched |
---|
194 | ); |
---|
195 | |
---|
196 | int pthread_attr_getinheritsched( |
---|
197 | const pthread_attr_t *attr, |
---|
198 | int *inheritsched |
---|
199 | ); |
---|
200 | |
---|
201 | int pthread_attr_setschedpolicy( |
---|
202 | pthread_attr_t *attr, |
---|
203 | int policy |
---|
204 | ); |
---|
205 | |
---|
206 | int pthread_attr_getschedpolicy( |
---|
207 | const pthread_attr_t *attr, |
---|
208 | int *policy |
---|
209 | ); |
---|
210 | |
---|
211 | #endif /* defined(_POSIX_THREAD_PRIORITY_SCHEDULING) */ |
---|
212 | |
---|
213 | int pthread_attr_setschedparam( |
---|
214 | pthread_attr_t *attr, |
---|
215 | const struct sched_param *param |
---|
216 | ); |
---|
217 | |
---|
218 | int pthread_attr_getschedparam( |
---|
219 | const pthread_attr_t *attr, |
---|
220 | struct sched_param *param |
---|
221 | ); |
---|
222 | |
---|
223 | #if defined(_POSIX_THREAD_PRIORITY_SCHEDULING) |
---|
224 | |
---|
225 | /* |
---|
226 | * 13.5.2 Dynamic Thread Scheduling Parameters Access, |
---|
227 | * P1003.1c/Draft 10, p. 124 |
---|
228 | */ |
---|
229 | |
---|
230 | int pthread_getschedparam( |
---|
231 | pthread_t thread, |
---|
232 | int *policy, |
---|
233 | struct sched_param *param |
---|
234 | ); |
---|
235 | |
---|
236 | int pthread_setschedparam( |
---|
237 | pthread_t thread, |
---|
238 | int policy, |
---|
239 | struct sched_param *param |
---|
240 | ); |
---|
241 | |
---|
242 | #endif /* defined(_POSIX_THREAD_PRIORITY_SCHEDULING) */ |
---|
243 | |
---|
244 | #if defined(_POSIX_THREAD_PRIO_INHERIT) || defined(_POSIX_THREAD_PRIO_PROTECT) |
---|
245 | |
---|
246 | /* |
---|
247 | * 13.6.1 Mutex Initialization Scheduling Attributes, P1003.1c/Draft 10, p. 128 |
---|
248 | */ |
---|
249 | |
---|
250 | /* |
---|
251 | * Values for protocol. |
---|
252 | */ |
---|
253 | |
---|
254 | #define PTHREAD_PRIO_NONE 0 |
---|
255 | #define PTHREAD_PRIO_INHERIT 1 |
---|
256 | #define PTHREAD_PRIO_PROTECT 2 |
---|
257 | |
---|
258 | int pthread_mutexattr_setprotocol( |
---|
259 | pthread_mutexattr_t *attr, |
---|
260 | int protocol |
---|
261 | ); |
---|
262 | |
---|
263 | int pthread_mutexattr_getprotocol( |
---|
264 | const pthread_mutexattr_t *attr, |
---|
265 | int *protocol |
---|
266 | ); |
---|
267 | |
---|
268 | int pthread_mutexattr_setprioceiling( |
---|
269 | pthread_mutexattr_t *attr, |
---|
270 | int prioceiling |
---|
271 | ); |
---|
272 | |
---|
273 | int pthread_mutexattr_getprioceiling( |
---|
274 | const pthread_mutexattr_t *attr, |
---|
275 | int *prioceiling |
---|
276 | ); |
---|
277 | |
---|
278 | #endif /* _POSIX_THREAD_PRIO_INHERIT || _POSIX_THREAD_PRIO_PROTECT */ |
---|
279 | |
---|
280 | #if defined(_POSIX_THREAD_PRIO_PROTECT) |
---|
281 | |
---|
282 | /* |
---|
283 | * 13.6.2 Change the Priority Ceiling of a Mutex, P1003.1c/Draft 10, p. 131 |
---|
284 | */ |
---|
285 | |
---|
286 | int pthread_mutex_setprioceiling( |
---|
287 | pthread_mutex_t *mutex, |
---|
288 | int prioceiling, |
---|
289 | int *old_ceiling |
---|
290 | ); |
---|
291 | |
---|
292 | int pthread_mutex_getprioceiling( |
---|
293 | pthread_mutex_t *mutex, |
---|
294 | int *prioceiling |
---|
295 | ); |
---|
296 | |
---|
297 | #endif /* _POSIX_THREAD_PRIO_PROTECT */ |
---|
298 | |
---|
299 | /* |
---|
300 | * 16.1.1 Thread Creation Attributes, P1003.1c/Draft 10, p, 140 |
---|
301 | */ |
---|
302 | |
---|
303 | int pthread_attr_init( |
---|
304 | pthread_attr_t *attr |
---|
305 | ); |
---|
306 | |
---|
307 | int pthread_attr_destroy( |
---|
308 | pthread_attr_t *attr |
---|
309 | ); |
---|
310 | |
---|
311 | int pthread_attr_getstacksize( |
---|
312 | const pthread_attr_t *attr, |
---|
313 | size_t *stacksize |
---|
314 | ); |
---|
315 | |
---|
316 | int pthread_attr_setstacksize( |
---|
317 | pthread_attr_t *attr, |
---|
318 | size_t stacksize |
---|
319 | ); |
---|
320 | |
---|
321 | int pthread_attr_getstackaddr( |
---|
322 | const pthread_attr_t *attr, |
---|
323 | void **stackaddr |
---|
324 | ); |
---|
325 | |
---|
326 | int pthread_attr_setstackaddr( |
---|
327 | pthread_attr_t *attr, |
---|
328 | void *stackaddr |
---|
329 | ); |
---|
330 | |
---|
331 | int pthread_attr_getdetachstate( |
---|
332 | const pthread_attr_t *attr, |
---|
333 | int *detachstate |
---|
334 | ); |
---|
335 | |
---|
336 | int pthread_attr_setdetachstate( |
---|
337 | pthread_attr_t *attr, |
---|
338 | int detachstate |
---|
339 | ); |
---|
340 | |
---|
341 | /* |
---|
342 | * 16.1.2 Thread Creation, P1003.1c/Draft 10, p. 144 |
---|
343 | */ |
---|
344 | |
---|
345 | int pthread_create( |
---|
346 | pthread_t *thread, |
---|
347 | const pthread_attr_t *attr, |
---|
348 | void *(*start_routine)( void * ), |
---|
349 | void *arg |
---|
350 | ); |
---|
351 | |
---|
352 | /* |
---|
353 | * 16.1.3 Wait for Thread Termination, P1003.1c/Draft 10, p. 147 |
---|
354 | */ |
---|
355 | |
---|
356 | int pthread_join( |
---|
357 | pthread_t thread, |
---|
358 | void **value_ptr |
---|
359 | ); |
---|
360 | |
---|
361 | /* |
---|
362 | * 16.1.4 Detaching a Thread, P1003.1c/Draft 10, p. 149 |
---|
363 | */ |
---|
364 | |
---|
365 | int pthread_detach( |
---|
366 | pthread_t thread |
---|
367 | ); |
---|
368 | |
---|
369 | /* |
---|
370 | * 16.1.5.1 Thread Termination, p1003.1c/Draft 10, p. 150 |
---|
371 | */ |
---|
372 | |
---|
373 | void pthread_exit( |
---|
374 | void *value_ptr |
---|
375 | ); |
---|
376 | |
---|
377 | /* |
---|
378 | * 16.1.6 Get Calling Thread's ID, p1003.1c/Draft 10, p. XXX |
---|
379 | */ |
---|
380 | |
---|
381 | pthread_t pthread_self( void ); |
---|
382 | |
---|
383 | /* |
---|
384 | * 16.1.7 Compare Thread IDs, p1003.1c/Draft 10, p. 153 |
---|
385 | */ |
---|
386 | |
---|
387 | int pthread_equal( |
---|
388 | pthread_t t1, |
---|
389 | pthread_t t2 |
---|
390 | ); |
---|
391 | |
---|
392 | /* |
---|
393 | * 16.1.8 Dynamic Package Initialization |
---|
394 | */ |
---|
395 | |
---|
396 | /* |
---|
397 | * This is used to statically initialize a pthread_once_t. Example: |
---|
398 | * |
---|
399 | * pthread_once_t once = PTHREAD_ONCE_INIT; |
---|
400 | * |
---|
401 | * NOTE: This is named inconsistently -- it should be INITIALIZER. |
---|
402 | */ |
---|
403 | |
---|
404 | #define PTHREAD_ONCE_INIT { 1, 0 } /* is initialized and not run */ |
---|
405 | |
---|
406 | int pthread_once( |
---|
407 | pthread_once_t *once_control, |
---|
408 | void (*init_routine)(void) |
---|
409 | ); |
---|
410 | |
---|
411 | /* |
---|
412 | * 17.1.1 Thread-Specific Data Key Create, P1003.1c/Draft 10, p. 163 |
---|
413 | */ |
---|
414 | |
---|
415 | int pthread_key_create( |
---|
416 | pthread_key_t *key, |
---|
417 | void (*destructor)( void * ) |
---|
418 | ); |
---|
419 | |
---|
420 | /* |
---|
421 | * 17.1.2 Thread-Specific Data Management, P1003.1c/Draft 10, p. 165 |
---|
422 | */ |
---|
423 | |
---|
424 | int pthread_setspecific( |
---|
425 | pthread_key_t key, |
---|
426 | const void *value |
---|
427 | ); |
---|
428 | |
---|
429 | void *pthread_getspecific( |
---|
430 | pthread_key_t key |
---|
431 | ); |
---|
432 | |
---|
433 | /* |
---|
434 | * 17.1.3 Thread-Specific Data Key Deletion, P1003.1c/Draft 10, p. 167 |
---|
435 | */ |
---|
436 | |
---|
437 | int pthread_key_delete( |
---|
438 | pthread_key_t key |
---|
439 | ); |
---|
440 | |
---|
441 | /* |
---|
442 | * 18.2.1 Canceling Execution of a Thread, P1003.1c/Draft 10, p. 181 |
---|
443 | */ |
---|
444 | |
---|
445 | #define PTHREAD_CANCEL_ENABLE 0 |
---|
446 | #define PTHREAD_CANCEL_DISABLE 1 |
---|
447 | |
---|
448 | #define PTHREAD_CANCEL_DEFERRED 0 |
---|
449 | #define PTHREAD_CANCEL_ASYNCHRONOUS 1 |
---|
450 | |
---|
451 | int pthread_cancel( |
---|
452 | pthread_t thread |
---|
453 | ); |
---|
454 | |
---|
455 | /* |
---|
456 | * 18.2.2 Setting Cancelability State, P1003.1c/Draft 10, p. 183 |
---|
457 | */ |
---|
458 | |
---|
459 | int pthread_setcancelstate( |
---|
460 | int state, |
---|
461 | int *oldstate |
---|
462 | ); |
---|
463 | |
---|
464 | int pthread_setcanceltype( |
---|
465 | int type, |
---|
466 | int *oldtype |
---|
467 | ); |
---|
468 | |
---|
469 | void pthread_testcancel( void ); |
---|
470 | |
---|
471 | /* |
---|
472 | * 18.2.3.1 Establishing Cancellation Handlers, P1003.1c/Draft 10, p. 184 |
---|
473 | */ |
---|
474 | |
---|
475 | void pthread_cleanup_push( |
---|
476 | void (*routine)( void * ), |
---|
477 | void *arg |
---|
478 | ); |
---|
479 | |
---|
480 | void pthread_cleanup_pop( |
---|
481 | int execute |
---|
482 | ); |
---|
483 | |
---|
484 | #if defined(_POSIX_THREAD_CPUTIME) |
---|
485 | |
---|
486 | /* |
---|
487 | * 20.1.6 Accessing a Thread CPU-time Clock, P1003.4b/D8, p. 58 |
---|
488 | */ |
---|
489 | |
---|
490 | int pthread_getcpuclockid( |
---|
491 | pthread_t thread_id, |
---|
492 | clockid_t *clock_id |
---|
493 | ); |
---|
494 | |
---|
495 | /* |
---|
496 | * 20.1.7 CPU-time Clock Thread Creation Attribute, P1003.4b/D8, p. 59 |
---|
497 | */ |
---|
498 | |
---|
499 | int pthread_attr_setcputime( |
---|
500 | pthread_attr_t *attr, |
---|
501 | int clock_allowed |
---|
502 | ); |
---|
503 | |
---|
504 | int pthread_attr_getcputime( |
---|
505 | pthread_attr_t *attr, |
---|
506 | int *clock_allowed |
---|
507 | ); |
---|
508 | |
---|
509 | #endif /* defined(_POSIX_THREAD_CPUTIME) */ |
---|
510 | |
---|
511 | #endif /* defined(_POSIX_THREADS) */ |
---|
512 | #endif |
---|
513 | /* end of include file */ |
---|