source: trunk/libs/newlib/src/newlib/libc/include/pthread.h @ 444

Last change on this file since 444 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 14.3 KB
Line 
1/*
2 *  Written by Joel Sherrill <joel.sherrill@OARcorp.com>.
3 *
4 *  COPYRIGHT (c) 1989-2013, 2015.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  Permission to use, copy, modify, and distribute this software for any
8 *  purpose without fee is hereby granted, provided that this entire notice
9 *  is included in all copies of any software which is or includes a copy
10 *  or modification of this software.
11 *
12 *  THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
13 *  WARRANTY.  IN PARTICULAR,  THE AUTHOR MAKES NO REPRESENTATION
14 *  OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY OF THIS
15 *  SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
16 */
17
18#ifndef __PTHREAD_h
19#define __PTHREAD_h
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25#include <unistd.h>
26
27#if defined(_POSIX_THREADS)
28
29#include <sys/types.h>
30#include <time.h>
31#include <sched.h>
32#include <sys/cdefs.h>
33
34struct _pthread_cleanup_context {
35  void (*_routine)(void *);
36  void *_arg;
37  int _canceltype;
38  struct _pthread_cleanup_context *_previous;
39};
40
41/* Register Fork Handlers */
42int     pthread_atfork (void (*prepare)(void), void (*parent)(void),
43                   void (*child)(void));
44         
45/* Mutex Initialization Attributes, P1003.1c/Draft 10, p. 81 */
46
47int     pthread_mutexattr_init (pthread_mutexattr_t *__attr);
48int     pthread_mutexattr_destroy (pthread_mutexattr_t *__attr);
49int     pthread_mutexattr_getpshared (const pthread_mutexattr_t *__attr,
50                                      int  *__pshared);
51int     pthread_mutexattr_setpshared (pthread_mutexattr_t *__attr,
52                                      int __pshared);
53
54#if defined(_UNIX98_THREAD_MUTEX_ATTRIBUTES)
55
56/* Single UNIX Specification 2 Mutex Attributes types */
57
58int pthread_mutexattr_gettype (const pthread_mutexattr_t *__attr, int *__kind);
59int pthread_mutexattr_settype (pthread_mutexattr_t *__attr, int __kind);
60
61#endif
62
63/* Initializing and Destroying a Mutex, P1003.1c/Draft 10, p. 87 */
64
65int     pthread_mutex_init (pthread_mutex_t *__mutex,
66                            const pthread_mutexattr_t *__attr);
67int     pthread_mutex_destroy (pthread_mutex_t *__mutex);
68
69/* This is used to statically initialize a pthread_mutex_t. Example:
70 
71    pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
72 */
73
74#define PTHREAD_MUTEX_INITIALIZER _PTHREAD_MUTEX_INITIALIZER
75
76/*  Locking and Unlocking a Mutex, P1003.1c/Draft 10, p. 93
77    NOTE: P1003.4b/D8 adds pthread_mutex_timedlock(), p. 29 */
78
79int     pthread_mutex_lock (pthread_mutex_t *__mutex);
80int     pthread_mutex_trylock (pthread_mutex_t *__mutex);
81int     pthread_mutex_unlock (pthread_mutex_t *__mutex);
82
83#if defined(_POSIX_TIMEOUTS)
84
85int     pthread_mutex_timedlock (pthread_mutex_t *__mutex,
86                                 const struct timespec *__timeout);
87
88#endif /* _POSIX_TIMEOUTS */
89
90/* Condition Variable Initialization Attributes, P1003.1c/Draft 10, p. 96 */
91 
92int     pthread_condattr_init (pthread_condattr_t *__attr);
93int     pthread_condattr_destroy (pthread_condattr_t *__attr);
94
95int     pthread_condattr_getclock (const pthread_condattr_t *__restrict __attr,
96                                   clockid_t *__restrict __clock_id);
97int     pthread_condattr_setclock (pthread_condattr_t *__attr,
98                                   clockid_t __clock_id);
99
100int     pthread_condattr_getpshared (const pthread_condattr_t *__attr,
101                                     int *__pshared);
102int     pthread_condattr_setpshared (pthread_condattr_t *__attr, int __pshared);
103 
104/* Initializing and Destroying a Condition Variable, P1003.1c/Draft 10, p. 87 */
105 
106int     pthread_cond_init (pthread_cond_t *__cond,
107                           const pthread_condattr_t *__attr);
108int     pthread_cond_destroy (pthread_cond_t *__mutex);
109 
110/* This is used to statically initialize a pthread_cond_t. Example:
111 
112    pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
113 */
114 
115#define PTHREAD_COND_INITIALIZER _PTHREAD_COND_INITIALIZER
116 
117/* Broadcasting and Signaling a Condition, P1003.1c/Draft 10, p. 101 */
118 
119int     pthread_cond_signal (pthread_cond_t *__cond);
120int     pthread_cond_broadcast (pthread_cond_t *__cond);
121 
122/* Waiting on a Condition, P1003.1c/Draft 10, p. 105 */
123 
124int     pthread_cond_wait (pthread_cond_t *__cond, pthread_mutex_t *__mutex);
125 
126int     pthread_cond_timedwait (pthread_cond_t *__cond,
127                                pthread_mutex_t *__mutex,
128                                const struct timespec *__abstime);
129 
130#if defined(_POSIX_THREAD_PRIORITY_SCHEDULING)
131
132/* Thread Creation Scheduling Attributes, P1003.1c/Draft 10, p. 120 */
133
134int     pthread_attr_setscope (pthread_attr_t *__attr, int __contentionscope);
135int     pthread_attr_getscope (const pthread_attr_t *__attr,
136                               int *__contentionscope);
137int     pthread_attr_setinheritsched (pthread_attr_t *__attr,
138                                      int __inheritsched);
139int     pthread_attr_getinheritsched (const pthread_attr_t *__attr,
140                                      int *__inheritsched);
141int     pthread_attr_setschedpolicy (pthread_attr_t *__attr, int __policy);
142int     pthread_attr_getschedpolicy (const pthread_attr_t *__attr,
143                                     int *__policy);
144
145#endif /* defined(_POSIX_THREAD_PRIORITY_SCHEDULING) */
146
147int     pthread_attr_setschedparam (pthread_attr_t *__attr,
148                                    const struct sched_param *__param);
149int     pthread_attr_getschedparam (const pthread_attr_t *__attr,
150                                    struct sched_param *__param);
151
152#if defined(_POSIX_THREAD_PRIORITY_SCHEDULING)
153
154/* Dynamic Thread Scheduling Parameters Access, P1003.1c/Draft 10, p. 124 */
155
156int     pthread_getschedparam (pthread_t __pthread, int *__policy,
157                               struct sched_param *__param);
158int     pthread_setschedparam (pthread_t __pthread, int __policy,
159                               struct sched_param *__param);
160
161/* Set Scheduling Priority of a Thread */
162int     pthread_setschedprio (pthread_t thread, int prio);
163
164#endif /* defined(_POSIX_THREAD_PRIORITY_SCHEDULING) */
165
166#if __GNU_VISIBLE
167int     pthread_getname_np(pthread_t, char *, size_t) __nonnull((2));
168
169int     pthread_setname_np(pthread_t, const char *) __nonnull((2));
170#endif
171
172#if defined(_POSIX_THREAD_PRIO_INHERIT) || defined(_POSIX_THREAD_PRIO_PROTECT)
173
174/* Mutex Initialization Scheduling Attributes, P1003.1c/Draft 10, p. 128 */
175 
176int     pthread_mutexattr_setprotocol (pthread_mutexattr_t *__attr,
177                                       int __protocol);
178int     pthread_mutexattr_getprotocol (const pthread_mutexattr_t *__attr,
179                                       int *__protocol);
180int     pthread_mutexattr_setprioceiling (pthread_mutexattr_t *__attr,
181                                          int __prioceiling);
182int     pthread_mutexattr_getprioceiling (const pthread_mutexattr_t *__attr,
183                                          int *__prioceiling);
184
185#endif /* _POSIX_THREAD_PRIO_INHERIT || _POSIX_THREAD_PRIO_PROTECT */
186
187#if defined(_POSIX_THREAD_PRIO_PROTECT)
188
189/* Change the Priority Ceiling of a Mutex, P1003.1c/Draft 10, p. 131 */
190
191int     pthread_mutex_setprioceiling (pthread_mutex_t *__mutex,
192                                      int __prioceiling, int *__old_ceiling);
193int     pthread_mutex_getprioceiling (pthread_mutex_t *__mutex,
194                                      int *__prioceiling);
195
196#endif /* _POSIX_THREAD_PRIO_PROTECT */
197
198/* Thread Creation Attributes, P1003.1c/Draft 10, p, 140 */
199
200int     pthread_attr_init (pthread_attr_t *__attr);
201int     pthread_attr_destroy (pthread_attr_t *__attr);
202int     pthread_attr_setstack (pthread_attr_t *attr,
203        void *__stackaddr, size_t __stacksize);
204int     pthread_attr_getstack (const pthread_attr_t *attr,
205        void **__stackaddr, size_t *__stacksize);
206int     pthread_attr_getstacksize (const pthread_attr_t *__attr,
207                                   size_t *__stacksize);
208int     pthread_attr_setstacksize (pthread_attr_t *__attr, size_t __stacksize);
209int     pthread_attr_getstackaddr (const pthread_attr_t *__attr,
210                                   void **__stackaddr);
211int     pthread_attr_setstackaddr (pthread_attr_t  *__attr, void *__stackaddr);
212int     pthread_attr_getdetachstate (const pthread_attr_t *__attr,
213                                     int *__detachstate);
214int     pthread_attr_setdetachstate (pthread_attr_t *__attr, int __detachstate);
215int     pthread_attr_getguardsize (const pthread_attr_t *__attr,
216                                   size_t *__guardsize);
217int     pthread_attr_setguardsize (pthread_attr_t *__attr, size_t __guardsize);
218
219/* POSIX thread APIs beyond the POSIX standard but provided
220 * in GNU/Linux. They may be provided by other OSes for
221 * compatibility.
222 */
223#if __GNU_VISIBLE
224#if defined(__rtems__)
225int     pthread_attr_setaffinity_np (pthread_attr_t *__attr,
226                                     size_t __cpusetsize,
227                                     const cpu_set_t *__cpuset);
228int     pthread_attr_getaffinity_np (const pthread_attr_t *__attr,
229                                     size_t __cpusetsize, cpu_set_t *__cpuset);
230
231int     pthread_setaffinity_np (pthread_t __id, size_t __cpusetsize,
232                                const cpu_set_t *__cpuset);
233int     pthread_getaffinity_np (const pthread_t __id, size_t __cpusetsize,
234                                cpu_set_t *__cpuset);
235
236int     pthread_getattr_np (pthread_t __id, pthread_attr_t *__attr);
237#endif /* defined(__rtems__) */
238#endif /* __GNU_VISIBLE */
239
240/* Thread Creation, P1003.1c/Draft 10, p. 144 */
241
242int     pthread_create (pthread_t *__pthread, const pthread_attr_t  *__attr,
243                        void *(*__start_routine)(void *), void *__arg);
244
245/* Wait for Thread Termination, P1003.1c/Draft 10, p. 147 */
246
247int     pthread_join (pthread_t __pthread, void **__value_ptr);
248
249/* Detaching a Thread, P1003.1c/Draft 10, p. 149 */
250
251int     pthread_detach (pthread_t __pthread);
252
253/* Thread Termination, p1003.1c/Draft 10, p. 150 */
254
255void    pthread_exit (void *__value_ptr) __dead2;
256
257/* Get Calling Thread's ID, p1003.1c/Draft 10, p. XXX */
258
259pthread_t       pthread_self (void);
260
261/* Compare Thread IDs, p1003.1c/Draft 10, p. 153 */
262
263int     pthread_equal (pthread_t __t1, pthread_t __t2);
264
265/* Retrieve ID of a Thread's CPU Time Clock */
266int     pthread_getcpuclockid (pthread_t thread, clockid_t *clock_id);
267
268/* Get/Set Current Thread's Concurrency Level */
269int     pthread_setconcurrency (int new_level);
270int     pthread_getconcurrency (void);
271
272#if __BSD_VISIBLE || __GNU_VISIBLE
273void    pthread_yield (void);
274#endif
275
276/* Dynamic Package Initialization */
277
278/* This is used to statically initialize a pthread_once_t. Example:
279 
280    pthread_once_t once = PTHREAD_ONCE_INIT;
281 
282    NOTE:  This is named inconsistently -- it should be INITIALIZER.  */
283 
284#define PTHREAD_ONCE_INIT _PTHREAD_ONCE_INIT
285 
286int     pthread_once (pthread_once_t *__once_control,
287                      void (*__init_routine)(void));
288
289/* Thread-Specific Data Key Create, P1003.1c/Draft 10, p. 163 */
290
291int     pthread_key_create (pthread_key_t *__key,
292                            void (*__destructor)(void *));
293
294/* Thread-Specific Data Management, P1003.1c/Draft 10, p. 165 */
295
296int     pthread_setspecific (pthread_key_t __key, const void *__value);
297void *  pthread_getspecific (pthread_key_t __key);
298
299/* Thread-Specific Data Key Deletion, P1003.1c/Draft 10, p. 167 */
300
301int     pthread_key_delete (pthread_key_t __key);
302
303/* Execution of a Thread, P1003.1c/Draft 10, p. 181 */
304
305#define PTHREAD_CANCEL_ENABLE  0
306#define PTHREAD_CANCEL_DISABLE 1
307
308#define PTHREAD_CANCEL_DEFERRED 0
309#define PTHREAD_CANCEL_ASYNCHRONOUS 1
310
311#define PTHREAD_CANCELED ((void *) -1)
312
313int     pthread_cancel (pthread_t __pthread);
314
315/* Setting Cancelability State, P1003.1c/Draft 10, p. 183 */
316
317int     pthread_setcancelstate (int __state, int *__oldstate);
318int     pthread_setcanceltype (int __type, int *__oldtype);
319void    pthread_testcancel (void);
320
321/* Establishing Cancellation Handlers, P1003.1c/Draft 10, p. 184 */
322
323void    _pthread_cleanup_push (struct _pthread_cleanup_context *_context,
324                               void (*_routine)(void *), void *_arg);
325
326void    _pthread_cleanup_pop (struct _pthread_cleanup_context *_context,
327                              int _execute);
328
329/* It is intentional to open and close the scope in two different macros */
330#define pthread_cleanup_push(_routine, _arg) \
331  do { \
332    struct _pthread_cleanup_context _pthread_clup_ctx; \
333    _pthread_cleanup_push(&_pthread_clup_ctx, (_routine), (_arg))
334
335#define pthread_cleanup_pop(_execute) \
336    _pthread_cleanup_pop(&_pthread_clup_ctx, (_execute)); \
337  } while (0)
338
339#if __GNU_VISIBLE
340void    _pthread_cleanup_push_defer (struct _pthread_cleanup_context *_context,
341                                     void (*_routine)(void *), void *_arg);
342
343void    _pthread_cleanup_pop_restore (struct _pthread_cleanup_context *_context,
344                                      int _execute);
345
346/* It is intentional to open and close the scope in two different macros */
347#define pthread_cleanup_push_defer_np(_routine, _arg) \
348  do { \
349    struct _pthread_cleanup_context _pthread_clup_ctx; \
350    _pthread_cleanup_push_defer(&_pthread_clup_ctx, (_routine), (_arg))
351
352#define pthread_cleanup_pop_restore_np(_execute) \
353    _pthread_cleanup_pop_restore(&_pthread_clup_ctx, (_execute)); \
354  } while (0)
355#endif /* __GNU_VISIBLE */
356
357#if defined(_POSIX_THREAD_CPUTIME)
358 
359/* Accessing a Thread CPU-time Clock, P1003.4b/D8, p. 58 */
360 
361int     pthread_getcpuclockid (pthread_t __pthread_id, clockid_t *__clock_id);
362 
363#endif /* defined(_POSIX_THREAD_CPUTIME) */
364
365
366#endif /* defined(_POSIX_THREADS) */
367
368#if defined(_POSIX_BARRIERS)
369
370int     pthread_barrierattr_init (pthread_barrierattr_t *__attr);
371int     pthread_barrierattr_destroy (pthread_barrierattr_t *__attr);
372int     pthread_barrierattr_getpshared (const pthread_barrierattr_t *__attr,
373                                        int *__pshared);
374int     pthread_barrierattr_setpshared (pthread_barrierattr_t *__attr,
375                                        int __pshared);
376
377#define PTHREAD_BARRIER_SERIAL_THREAD -1
378
379int     pthread_barrier_init (pthread_barrier_t *__barrier,
380                              const pthread_barrierattr_t *__attr,
381                              unsigned __count);
382int     pthread_barrier_destroy (pthread_barrier_t *__barrier);
383int     pthread_barrier_wait (pthread_barrier_t *__barrier);
384
385#endif /* defined(_POSIX_BARRIERS) */
386
387#if defined(_POSIX_SPIN_LOCKS)
388
389int     pthread_spin_init (pthread_spinlock_t *__spinlock, int __pshared);
390int     pthread_spin_destroy (pthread_spinlock_t *__spinlock);
391int     pthread_spin_lock (pthread_spinlock_t *__spinlock);
392int     pthread_spin_trylock (pthread_spinlock_t *__spinlock);
393int     pthread_spin_unlock (pthread_spinlock_t *__spinlock);
394
395#endif /* defined(_POSIX_SPIN_LOCKS) */
396
397#if defined(_POSIX_READER_WRITER_LOCKS)
398
399/* This is used to statically initialize a pthread_rwlock_t. Example:
400 
401    pthread_mutex_t mutex = PTHREAD_RWLOCK_INITIALIZER;
402 */
403
404#define PTHREAD_RWLOCK_INITIALIZER _PTHREAD_RWLOCK_INITIALIZER
405
406int     pthread_rwlockattr_init (pthread_rwlockattr_t *__attr);
407int     pthread_rwlockattr_destroy (pthread_rwlockattr_t *__attr);
408int     pthread_rwlockattr_getpshared (const pthread_rwlockattr_t *__attr,
409                                       int *__pshared);
410int     pthread_rwlockattr_setpshared (pthread_rwlockattr_t *__attr,
411                                       int __pshared);
412
413int     pthread_rwlock_init (pthread_rwlock_t *__rwlock,
414                             const pthread_rwlockattr_t *__attr);
415int     pthread_rwlock_destroy (pthread_rwlock_t *__rwlock);
416int     pthread_rwlock_rdlock (pthread_rwlock_t *__rwlock);
417int     pthread_rwlock_tryrdlock (pthread_rwlock_t *__rwlock);
418int     pthread_rwlock_timedrdlock (pthread_rwlock_t *__rwlock,
419                                    const struct timespec *__abstime);
420int     pthread_rwlock_unlock (pthread_rwlock_t *__rwlock);
421int     pthread_rwlock_wrlock (pthread_rwlock_t *__rwlock);
422int     pthread_rwlock_trywrlock (pthread_rwlock_t *__rwlock);
423int     pthread_rwlock_timedwrlock (pthread_rwlock_t *__rwlock,
424                                    const struct timespec *__abstime);
425
426#endif /* defined(_POSIX_READER_WRITER_LOCKS) */
427
428
429#ifdef __cplusplus
430}
431#endif
432
433#endif
434/* end of include file */
Note: See TracBrowser for help on using the repository browser.