]> git.saurik.com Git - apple/libc.git/blob - pthreads/pthread.h
d110560848facf30ca4bb60d10321b3aaf056043
[apple/libc.git] / pthreads / pthread.h
1 /*
2 * Copyright 1996 1995 by Open Software Foundation, Inc. 1997 1996 1995 1994 1993 1992 1991
3 * All Rights Reserved
4 *
5 * Permission to use, copy, modify, and distribute this software and
6 * its documentation for any purpose and without fee is hereby granted,
7 * provided that the above copyright notice appears in all copies and
8 * that both the copyright notice and this permission notice appear in
9 * supporting documentation.
10 *
11 * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
12 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
13 * FOR A PARTICULAR PURPOSE.
14 *
15 * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
16 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17 * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
18 * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
19 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 *
21 */
22 /*
23 * MkLinux
24 */
25
26 /*
27 * POSIX Threads - IEEE 1003.1c
28 */
29
30 #ifndef _POSIX_PTHREAD_H
31 #define _POSIX_PTHREAD_H
32
33 #ifndef __POSIX_LIB__
34 #include <pthread_impl.h>
35 #endif
36 #include <errno.h>
37 #include <sched.h>
38 #include <time.h>
39 #include <unistd.h>
40 #include <limits.h>
41 #include <signal.h>
42
43 #ifndef _POSIX_C_SOURCE
44 #include <mach/mach_types.h>
45 #endif /* ! _POSIX_C_SOURCE */
46
47 /*
48 * These symbols indicate which [optional] features are available
49 * They can be tested at compile time via '#ifdef XXX'
50 * The way to check for pthreads is like so:
51
52 * #include <unistd.h>
53 * #ifdef _POSIX_THREADS
54 * #include <pthread.h>
55 * #endif
56
57 */
58
59 /* These will be moved to unistd.h */
60
61
62 /* These two should be defined also */
63 #undef _POSIX_THREAD_PROCESS_SHARED
64 #undef _POSIX_THREAD_SAFE_FUNCTIONS
65
66 /*
67 * Note: These data structures are meant to be opaque. Only enough
68 * structure is exposed to support initializers.
69 * All of the typedefs will be moved to <sys/types.h>
70 */
71
72 #include <sys/cdefs.h>
73
74 __BEGIN_DECLS
75 /*
76 * Threads
77 */
78
79
80 /*
81 * Cancel cleanup handler management. Note, since these are implemented as macros,
82 * they *MUST* occur in matched pairs!
83 */
84
85 #define pthread_cleanup_push(func, val) \
86 { \
87 struct _pthread_handler_rec __handler; \
88 pthread_t __self = pthread_self(); \
89 __handler.routine = func; \
90 __handler.arg = val; \
91 __handler.next = __self->cleanup_stack; \
92 __self->cleanup_stack = &__handler;
93
94 #define pthread_cleanup_pop(execute) \
95 /* Note: 'handler' must be in this same lexical context! */ \
96 __self->cleanup_stack = __handler.next; \
97 if (execute) (__handler.routine)(__handler.arg); \
98 }
99
100 /*
101 * Thread attributes
102 */
103
104 #define PTHREAD_CREATE_JOINABLE 1
105 #define PTHREAD_CREATE_DETACHED 2
106
107 #define PTHREAD_INHERIT_SCHED 1
108 #define PTHREAD_EXPLICIT_SCHED 2
109
110 #define PTHREAD_CANCEL_ENABLE 0x01 /* Cancel takes place at next cancellation point */
111 #define PTHREAD_CANCEL_DISABLE 0x00 /* Cancel postponed */
112 #define PTHREAD_CANCEL_DEFERRED 0x02 /* Cancel waits until cancellation point */
113 #define PTHREAD_CANCEL_ASYNCHRONOUS 0x00 /* Cancel occurs immediately */
114
115 /* We only support PTHREAD_SCOPE_SYSTEM */
116 #define PTHREAD_SCOPE_SYSTEM 1
117 #define PTHREAD_SCOPE_PROCESS 2
118
119 /* We only support PTHREAD_PROCESS_PRIVATE */
120 #define PTHREAD_PROCESS_SHARED 1
121 #define PTHREAD_PROCESS_PRIVATE 2
122
123 /* Who defines this? */
124
125 #if !defined(ENOTSUP)
126 #define ENOTSUP 89
127 #endif
128 /*
129 * Mutex protocol attributes
130 */
131 #define PTHREAD_PRIO_NONE 0
132 #define PTHREAD_PRIO_INHERIT 1
133 #define PTHREAD_PRIO_PROTECT 2
134
135 /*
136 * Mutex type attributes
137 */
138 #define PTHREAD_MUTEX_NORMAL 0
139 #define PTHREAD_MUTEX_ERRORCHECK 1
140 #define PTHREAD_MUTEX_RECURSIVE 2
141 #define PTHREAD_MUTEX_DEFAULT PTHREAD_MUTEX_NORMAL
142 /*
143 * Mutex variables
144 */
145
146 #define PTHREAD_MUTEX_INITIALIZER {_PTHREAD_MUTEX_SIG_init, {}}
147
148 /*
149 * Condition variable attributes
150 */
151
152 /*
153 * Condition variables
154 */
155
156 #define PTHREAD_COND_INITIALIZER {_PTHREAD_COND_SIG_init, {}}
157
158 /*
159 * Initialization control (once) variables
160 */
161
162 #define PTHREAD_ONCE_INIT {_PTHREAD_ONCE_SIG_init, {}}
163
164 /*
165 * Thread Specific Data - keys
166 */
167
168 #include <sys/time.h>
169
170 /*
171 * Prototypes for all PTHREAD interfaces
172 */
173 int pthread_attr_destroy __P((pthread_attr_t *attr));
174 int pthread_attr_getdetachstate __P((const pthread_attr_t *attr,
175 int *detachstate));
176 int pthread_attr_getinheritsched __P((const pthread_attr_t *attr,
177 int *inheritsched));
178 int pthread_attr_getschedparam __P((const pthread_attr_t *attr,
179 struct sched_param *param));
180 int pthread_attr_getschedpolicy __P((const pthread_attr_t *attr,
181 int *policy));
182 int pthread_attr_getstackaddr __P((const pthread_attr_t *attr,
183 void **stackaddr));
184 int pthread_attr_getstacksize __P((const pthread_attr_t *attr,
185 size_t *stacksize));
186 int pthread_attr_getstack __P((const pthread_attr_t *attr,
187 void **stackaddr, size_t *stacksize));
188 int pthread_attr_init __P((pthread_attr_t *attr));
189 int pthread_attr_setdetachstate __P((pthread_attr_t *attr,
190 int detachstate));
191 int pthread_attr_setinheritsched __P((pthread_attr_t *attr,
192 int inheritsched));
193 int pthread_attr_setschedparam __P((pthread_attr_t *attr,
194 const struct sched_param *param));
195 int pthread_attr_setschedpolicy __P((pthread_attr_t *attr,
196 int policy));
197 int pthread_attr_setstackaddr __P((pthread_attr_t *attr,
198 void *stackaddr));
199 int pthread_attr_setstacksize __P((pthread_attr_t *attr,
200 size_t stacksize));
201 int pthread_attr_setstack __P((pthread_attr_t *attr,
202 void *stackaddr, size_t stacksize));
203 int pthread_cancel __P((pthread_t thread));
204 int pthread_setcancelstate __P((int state, int *oldstate));
205 int pthread_setcanceltype __P((int type, int *oldtype));
206 void pthread_testcancel __P((void));
207 int pthread_cond_broadcast __P((pthread_cond_t *cond));
208 int pthread_cond_destroy __P((pthread_cond_t *cond));
209 int pthread_cond_init __P((pthread_cond_t *cond,
210 const pthread_condattr_t *attr));
211 int pthread_cond_signal __P((pthread_cond_t *cond));
212 int pthread_cond_wait __P((pthread_cond_t *cond,
213 pthread_mutex_t *mutex));
214 int pthread_cond_timedwait __P((pthread_cond_t *cond,
215 pthread_mutex_t *mutex,
216 const struct timespec *abstime));
217 int pthread_condattr_init __P((pthread_condattr_t *attr));
218 int pthread_condattr_destroy __P((pthread_condattr_t *attr));
219 int pthread_condattr_getpshared __P((const pthread_condattr_t *attr,
220 int *pshared));
221 int pthread_condattr_setpshared __P((pthread_condattr_t *attr,
222 int pshared));
223 int pthread_create __P((pthread_t *thread,
224 const pthread_attr_t *attr,
225 void *(*start_routine)(void *),
226 void *arg));
227 int pthread_detach __P((pthread_t thread));
228 int pthread_equal __P((pthread_t t1,
229 pthread_t t2));
230 void pthread_exit __P((void *value_ptr));
231 int pthread_kill __P((pthread_t, int));
232 int pthread_sigmask __P((int, const sigset_t *, sigset_t *));
233 int sigwait __P((const sigset_t *, int *));
234 int pthread_getschedparam __P((pthread_t thread,
235 int *policy,
236 struct sched_param *param));
237 int pthread_join __P((pthread_t thread,
238 void **value_ptr));
239 int pthread_mutex_destroy __P((pthread_mutex_t *mutex));
240 int pthread_mutex_getprioceiling __P((const pthread_mutex_t *mutex,
241 int *prioceiling));
242 int pthread_mutex_init __P((pthread_mutex_t *mutex,
243 const pthread_mutexattr_t *attr));
244 int pthread_mutex_lock __P((pthread_mutex_t *mutex));
245 int pthread_mutex_setprioceiling __P((pthread_mutex_t *mutex,
246 int prioceiling,
247 int *old_prioceiling));
248 int pthread_mutex_trylock __P((pthread_mutex_t *mutex));
249 int pthread_mutex_unlock __P((pthread_mutex_t *mutex));
250 int pthread_mutexattr_destroy __P((pthread_mutexattr_t *attr));
251 int pthread_mutexattr_getprioceiling __P((const pthread_mutexattr_t *attr,
252 int *prioceiling));
253 int pthread_mutexattr_getprotocol __P((const pthread_mutexattr_t *attr,
254 int *protocol));
255 int pthread_mutexattr_getpshared __P((const pthread_mutexattr_t *attr,
256 int *pshared));
257 int pthread_mutexattr_gettype __P((const pthread_mutexattr_t *attr,
258 int *type));
259 int pthread_mutexattr_init __P((pthread_mutexattr_t *attr));
260 int pthread_mutexattr_setprioceiling __P((pthread_mutexattr_t *attr,
261 int prioceiling));
262 int pthread_mutexattr_setprotocol __P((pthread_mutexattr_t *attr,
263 int protocol));
264 int pthread_mutexattr_settype __P((pthread_mutexattr_t *attr,
265 int type));
266 int pthread_mutexattr_setpshared __P((pthread_mutexattr_t *attr,
267 int pshared));
268 int pthread_once __P((pthread_once_t *once_control,
269 void (*init_routine)(void)));
270 pthread_t pthread_self __P((void));
271 int pthread_setschedparam __P((pthread_t thread,
272 int policy,
273 const struct sched_param *param));
274 int pthread_key_create __P((pthread_key_t *key,
275 void (*destructor)(void *)));
276 int pthread_key_delete __P((pthread_key_t key));
277 int pthread_setspecific __P((pthread_key_t key,
278 const void *value));
279 void *pthread_getspecific __P((pthread_key_t key));
280 int pthread_attr_getscope __P((pthread_attr_t *, int *));
281 int pthread_attr_setscope __P((pthread_attr_t *, int));
282 int pthread_getconcurrency __P((void));
283 int pthread_setconcurrency __P((int));
284 int pthread_rwlock_destroy __P((pthread_rwlock_t * rwlock));
285 int pthread_rwlock_init __P((pthread_rwlock_t * rwlock,
286 const pthread_rwlockattr_t *attr));
287 int pthread_rwlock_rdlock __P((pthread_rwlock_t *rwlock));
288 int pthread_rwlock_tryrdlock __P((pthread_rwlock_t *rwlock));
289 int pthread_rwlock_wrlock __P((pthread_rwlock_t *rwlock));
290 int pthread_rwlock_trywrlock __P((pthread_rwlock_t *rwlock));
291 int pthread_rwlock_unlock __P((pthread_rwlock_t *rwlock));
292 int pthread_rwlockattr_init __P((pthread_rwlockattr_t *attr));
293 int pthread_rwlockattr_destroy __P((pthread_rwlockattr_t *attr));
294 int pthread_rwlockattr_getpshared __P((const pthread_rwlockattr_t *attr,
295 int *pshared));
296 int pthread_rwlockattr_setpshared __P((pthread_rwlockattr_t *attr,
297 int pshared));
298
299 #ifndef _POSIX_C_SOURCE
300 /* returns non-zero if pthread_create or cthread_fork have been called */
301 int pthread_is_threaded_np __P((void));
302
303 /* returns non-zero if the current thread is the main thread */
304 int pthread_main_np __P((void));
305
306 /* return the mach thread bound to the pthread */
307 mach_port_t pthread_mach_thread_np __P((pthread_t));
308 size_t pthread_get_stacksize_np __P((pthread_t));
309 void * pthread_get_stackaddr_np __P((pthread_t));
310
311 /* Like pthread_cond_signal(), but only wake up the specified pthread */
312 int pthread_cond_signal_thread_np __P((pthread_cond_t *, pthread_t));
313
314 /* Like pthread_cond_timedwait, but use a relative timeout */
315 int pthread_cond_timedwait_relative_np __P((pthread_cond_t *cond,
316 pthread_mutex_t *mutex,
317 const struct timespec *reltime));
318
319 /* Like pthread_create(), but leaves the thread suspended */
320 int pthread_create_suspended_np __P((pthread_t *thread,
321 const pthread_attr_t *attr,
322 void *(*start_routine)(void *),
323 void *arg));
324 void pthread_yield_np __P((void));
325 #endif /* ! _POSIX_C_SOURCE */
326 __END_DECLS
327 #endif /* _POSIX_PTHREAD_H */