]> git.saurik.com Git - apple/libc.git/blame - pthreads/pthread.h
Libc-339.tar.gz
[apple/libc.git] / pthreads / pthread.h
CommitLineData
9385eb3d
A
1/*
2 * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
59e0d9fe
A
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
9385eb3d
A
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 */
e9ce8d39
A
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>
e9ce8d39
A
63#include <unistd.h>
64#include <limits.h>
5b2abdfb 65#include <signal.h>
59e0d9fe 66#include <sys/types.h> /* temporary - need to fix correctly */
5b2abdfb
A
67
68#ifndef _POSIX_C_SOURCE
69#include <mach/mach_types.h>
70#endif /* ! _POSIX_C_SOURCE */
e9ce8d39
A
71
72/*
73 * These symbols indicate which [optional] features are available
74 * They can be tested at compile time via '#ifdef XXX'
75 * The way to check for pthreads is like so:
76
77 * #include <unistd.h>
78 * #ifdef _POSIX_THREADS
79 * #include <pthread.h>
80 * #endif
81
82 */
83
84/* These will be moved to unistd.h */
85
e9ce8d39
A
86/*
87 * Note: These data structures are meant to be opaque. Only enough
88 * structure is exposed to support initializers.
89 * All of the typedefs will be moved to <sys/types.h>
90 */
91
92#include <sys/cdefs.h>
93
94__BEGIN_DECLS
95/*
96 * Threads
97 */
98
99
100/*
101 * Cancel cleanup handler management. Note, since these are implemented as macros,
102 * they *MUST* occur in matched pairs!
103 */
104
105#define pthread_cleanup_push(func, val) \
106 { \
107 struct _pthread_handler_rec __handler; \
108 pthread_t __self = pthread_self(); \
109 __handler.routine = func; \
110 __handler.arg = val; \
111 __handler.next = __self->cleanup_stack; \
112 __self->cleanup_stack = &__handler;
113
114#define pthread_cleanup_pop(execute) \
115 /* Note: 'handler' must be in this same lexical context! */ \
116 __self->cleanup_stack = __handler.next; \
117 if (execute) (__handler.routine)(__handler.arg); \
118 }
119
120/*
121 * Thread attributes
122 */
123
124#define PTHREAD_CREATE_JOINABLE 1
125#define PTHREAD_CREATE_DETACHED 2
126
127#define PTHREAD_INHERIT_SCHED 1
128#define PTHREAD_EXPLICIT_SCHED 2
129
130#define PTHREAD_CANCEL_ENABLE 0x01 /* Cancel takes place at next cancellation point */
131#define PTHREAD_CANCEL_DISABLE 0x00 /* Cancel postponed */
132#define PTHREAD_CANCEL_DEFERRED 0x02 /* Cancel waits until cancellation point */
133#define PTHREAD_CANCEL_ASYNCHRONOUS 0x00 /* Cancel occurs immediately */
134
135/* We only support PTHREAD_SCOPE_SYSTEM */
136#define PTHREAD_SCOPE_SYSTEM 1
137#define PTHREAD_SCOPE_PROCESS 2
138
5b2abdfb
A
139/* We only support PTHREAD_PROCESS_PRIVATE */
140#define PTHREAD_PROCESS_SHARED 1
141#define PTHREAD_PROCESS_PRIVATE 2
142
e9ce8d39
A
143/* Who defines this? */
144
145#if !defined(ENOTSUP)
146#define ENOTSUP 89
147#endif
148/*
5b2abdfb 149 * Mutex protocol attributes
e9ce8d39
A
150 */
151#define PTHREAD_PRIO_NONE 0
152#define PTHREAD_PRIO_INHERIT 1
153#define PTHREAD_PRIO_PROTECT 2
154
5b2abdfb
A
155/*
156 * Mutex type attributes
157 */
158#define PTHREAD_MUTEX_NORMAL 0
159#define PTHREAD_MUTEX_ERRORCHECK 1
160#define PTHREAD_MUTEX_RECURSIVE 2
161#define PTHREAD_MUTEX_DEFAULT PTHREAD_MUTEX_NORMAL
e9ce8d39
A
162/*
163 * Mutex variables
164 */
165
9385eb3d 166#define PTHREAD_MUTEX_INITIALIZER {_PTHREAD_MUTEX_SIG_init, {0}}
e9ce8d39
A
167
168/*
169 * Condition variable attributes
170 */
171
172/*
173 * Condition variables
174 */
175
9385eb3d 176#define PTHREAD_COND_INITIALIZER {_PTHREAD_COND_SIG_init, {0}}
e9ce8d39
A
177
178/*
179 * Initialization control (once) variables
180 */
181
9385eb3d 182#define PTHREAD_ONCE_INIT {_PTHREAD_ONCE_SIG_init, {0}}
e9ce8d39
A
183
184/*
185 * Thread Specific Data - keys
186 */
187
188#include <sys/time.h>
189
190/*
191 * Prototypes for all PTHREAD interfaces
192 */
9385eb3d
A
193int pthread_attr_destroy(pthread_attr_t *attr);
194int pthread_attr_getdetachstate(const pthread_attr_t *attr,
195 int *detachstate);
196int pthread_attr_getinheritsched(const pthread_attr_t *attr,
197 int *inheritsched);
198int pthread_attr_getschedparam(const pthread_attr_t *attr,
199 struct sched_param *param);
200int pthread_attr_getschedpolicy(const pthread_attr_t *attr,
201 int *policy);
202int pthread_attr_getstackaddr(const pthread_attr_t *attr,
203 void **stackaddr);
204int pthread_attr_getstacksize(const pthread_attr_t *attr,
205 size_t *stacksize);
206int pthread_attr_getstack(const pthread_attr_t *attr,
207 void **stackaddr, size_t *stacksize);
208int pthread_attr_getguardsize(const pthread_attr_t *attr,
209 size_t *guardsize);
210int pthread_attr_init(pthread_attr_t *attr);
211int pthread_attr_setdetachstate(pthread_attr_t *attr,
212 int detachstate);
213int pthread_attr_setinheritsched(pthread_attr_t *attr,
214 int inheritsched);
215int pthread_attr_setschedparam(pthread_attr_t *attr,
216 const struct sched_param *param);
217int pthread_attr_setschedpolicy(pthread_attr_t *attr,
218 int policy);
219int pthread_attr_setstackaddr(pthread_attr_t *attr,
220 void *stackaddr);
221int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize);
222int pthread_attr_setguardsize(pthread_attr_t *attr, size_t guardsize);
223int pthread_attr_setstack(pthread_attr_t *attr,
224 void *stackaddr, size_t stacksize);
225int pthread_cancel(pthread_t thread);
226int pthread_setcancelstate(int state, int *oldstate);
227int pthread_setcanceltype(int type, int *oldtype);
228void pthread_testcancel(void);
229int pthread_cond_broadcast(pthread_cond_t *cond);
230int pthread_cond_destroy(pthread_cond_t *cond);
231int pthread_cond_init(pthread_cond_t *cond,
232 const pthread_condattr_t *attr);
233int pthread_cond_signal(pthread_cond_t *cond);
234int pthread_cond_wait(pthread_cond_t *cond,
235 pthread_mutex_t *mutex);
236int pthread_cond_timedwait(pthread_cond_t *cond,
e9ce8d39 237 pthread_mutex_t *mutex,
9385eb3d
A
238 const struct timespec *abstime);
239int pthread_condattr_init(pthread_condattr_t *attr);
240int pthread_condattr_destroy(pthread_condattr_t *attr);
241int pthread_condattr_getpshared(const pthread_condattr_t *attr,
242 int *pshared);
243int pthread_condattr_setpshared(pthread_condattr_t *attr,
244 int pshared);
245int pthread_create(pthread_t *thread,
e9ce8d39
A
246 const pthread_attr_t *attr,
247 void *(*start_routine)(void *),
9385eb3d
A
248 void *arg);
249int pthread_detach(pthread_t thread);
250int pthread_equal(pthread_t t1,
251 pthread_t t2);
252void pthread_exit(void *value_ptr) __dead2;
253int pthread_kill(pthread_t, int);
254int pthread_sigmask(int, const sigset_t *, sigset_t *);
255int pthread_getschedparam(pthread_t thread,
e9ce8d39 256 int *policy,
9385eb3d
A
257 struct sched_param *param);
258int pthread_join(pthread_t thread,
259 void **value_ptr);
260int pthread_mutex_destroy(pthread_mutex_t *mutex);
261int pthread_mutex_getprioceiling(const pthread_mutex_t *mutex,
262 int *prioceiling);
263int pthread_mutex_init(pthread_mutex_t *mutex,
264 const pthread_mutexattr_t *attr);
265int pthread_mutex_lock(pthread_mutex_t *mutex);
266int pthread_mutex_setprioceiling(pthread_mutex_t *mutex,
e9ce8d39 267 int prioceiling,
9385eb3d
A
268 int *old_prioceiling);
269int pthread_mutex_trylock(pthread_mutex_t *mutex);
270int pthread_mutex_unlock(pthread_mutex_t *mutex);
271int pthread_mutexattr_destroy(pthread_mutexattr_t *attr);
272int pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *attr,
273 int *prioceiling);
274int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *attr,
275 int *protocol);
276int pthread_mutexattr_getpshared(const pthread_mutexattr_t *attr,
277 int *pshared);
278int pthread_mutexattr_gettype(const pthread_mutexattr_t *attr,
279 int *type);
280int pthread_mutexattr_init(pthread_mutexattr_t *attr);
281int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *attr,
282 int prioceiling);
283int pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr,
284 int protocol);
285int pthread_mutexattr_settype(pthread_mutexattr_t *attr,
286 int type);
287int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr,
288 int pshared);
289int pthread_once(pthread_once_t *once_control,
290 void (*init_routine)(void));
291pthread_t pthread_self(void);
292int pthread_setschedparam(pthread_t thread,
e9ce8d39 293 int policy,
9385eb3d
A
294 const struct sched_param *param);
295int pthread_key_create(pthread_key_t *key,
296 void (*destructor)(void *));
297int pthread_key_delete(pthread_key_t key);
298int pthread_setspecific(pthread_key_t key,
299 const void *value);
300void *pthread_getspecific(pthread_key_t key);
301int pthread_attr_getscope(pthread_attr_t *, int *);
302int pthread_attr_setscope(pthread_attr_t *, int);
303int pthread_getconcurrency(void);
304int pthread_setconcurrency(int);
305int pthread_rwlock_destroy(pthread_rwlock_t * rwlock);
306int pthread_rwlock_init(pthread_rwlock_t * rwlock,
307 const pthread_rwlockattr_t *attr);
308int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock);
309int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock);
310int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock);
311int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock);
312int pthread_rwlock_unlock(pthread_rwlock_t *rwlock);
313int pthread_rwlockattr_init(pthread_rwlockattr_t *attr);
314int pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr);
315int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *attr,
316 int *pshared);
317int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *attr,
318 int pshared);
5b2abdfb
A
319
320#ifndef _POSIX_C_SOURCE
e9ce8d39 321/* returns non-zero if pthread_create or cthread_fork have been called */
9385eb3d 322int pthread_is_threaded_np(void);
e9ce8d39 323
5b2abdfb 324/* returns non-zero if the current thread is the main thread */
9385eb3d 325int pthread_main_np(void);
5b2abdfb 326
e9ce8d39 327/* return the mach thread bound to the pthread */
9385eb3d
A
328mach_port_t pthread_mach_thread_np(pthread_t);
329size_t pthread_get_stacksize_np(pthread_t);
330void * pthread_get_stackaddr_np(pthread_t);
e9ce8d39
A
331
332/* Like pthread_cond_signal(), but only wake up the specified pthread */
9385eb3d 333int pthread_cond_signal_thread_np(pthread_cond_t *, pthread_t);
e9ce8d39 334
5b2abdfb 335/* Like pthread_cond_timedwait, but use a relative timeout */
9385eb3d 336int pthread_cond_timedwait_relative_np(pthread_cond_t *cond,
5b2abdfb 337 pthread_mutex_t *mutex,
9385eb3d 338 const struct timespec *reltime);
5b2abdfb 339
e9ce8d39 340/* Like pthread_create(), but leaves the thread suspended */
9385eb3d 341int pthread_create_suspended_np(pthread_t *thread,
e9ce8d39
A
342 const pthread_attr_t *attr,
343 void *(*start_routine)(void *),
9385eb3d
A
344 void *arg);
345void pthread_yield_np(void);
5b2abdfb 346#endif /* ! _POSIX_C_SOURCE */
e9ce8d39
A
347__END_DECLS
348#endif /* _POSIX_PTHREAD_H */