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