]> git.saurik.com Git - apple/libc.git/blob - pthreads.subproj/pthread.h
0f1ea581ced01e35474d340a8c17702d55d8f5e8
[apple/libc.git] / pthreads.subproj / 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 <mach/mach_types.h>
40 #include <unistd.h>
41 #include <limits.h>
42
43 /*
44 * These symbols indicate which [optional] features are available
45 * They can be tested at compile time via '#ifdef XXX'
46 * The way to check for pthreads is like so:
47
48 * #include <unistd.h>
49 * #ifdef _POSIX_THREADS
50 * #include <pthread.h>
51 * #endif
52
53 */
54
55 /* These will be moved to unistd.h */
56
57
58 /* These two should be defined also */
59 #undef _POSIX_THREAD_PROCESS_SHARED
60 #undef _POSIX_THREAD_SAFE_FUNCTIONS
61
62 /*
63 * Note: These data structures are meant to be opaque. Only enough
64 * structure is exposed to support initializers.
65 * All of the typedefs will be moved to <sys/types.h>
66 */
67
68 #include <sys/cdefs.h>
69
70 __BEGIN_DECLS
71 /*
72 * Threads
73 */
74
75
76 /*
77 * Cancel cleanup handler management. Note, since these are implemented as macros,
78 * they *MUST* occur in matched pairs!
79 */
80
81 #define pthread_cleanup_push(func, val) \
82 { \
83 struct _pthread_handler_rec __handler; \
84 pthread_t __self = pthread_self(); \
85 __handler.routine = func; \
86 __handler.arg = val; \
87 __handler.next = __self->cleanup_stack; \
88 __self->cleanup_stack = &__handler;
89
90 #define pthread_cleanup_pop(execute) \
91 /* Note: 'handler' must be in this same lexical context! */ \
92 __self->cleanup_stack = __handler.next; \
93 if (execute) (__handler.routine)(__handler.arg); \
94 }
95
96 /*
97 * Thread attributes
98 */
99
100 #define PTHREAD_CREATE_JOINABLE 1
101 #define PTHREAD_CREATE_DETACHED 2
102
103 #define PTHREAD_INHERIT_SCHED 1
104 #define PTHREAD_EXPLICIT_SCHED 2
105
106 #define PTHREAD_CANCEL_ENABLE 0x01 /* Cancel takes place at next cancellation point */
107 #define PTHREAD_CANCEL_DISABLE 0x00 /* Cancel postponed */
108 #define PTHREAD_CANCEL_DEFERRED 0x02 /* Cancel waits until cancellation point */
109 #define PTHREAD_CANCEL_ASYNCHRONOUS 0x00 /* Cancel occurs immediately */
110
111 /* We only support PTHREAD_SCOPE_SYSTEM */
112 #define PTHREAD_SCOPE_SYSTEM 1
113 #define PTHREAD_SCOPE_PROCESS 2
114
115 /* Who defines this? */
116
117 #if !defined(ENOTSUP)
118 #define ENOTSUP 89
119 #endif
120 /*
121 * Mutex attributes
122 */
123 #define PTHREAD_PRIO_NONE 0
124 #define PTHREAD_PRIO_INHERIT 1
125 #define PTHREAD_PRIO_PROTECT 2
126
127 /*
128 * Mutex variables
129 */
130
131 #define PTHREAD_MUTEX_INITIALIZER {_PTHREAD_MUTEX_SIG_init}
132
133 /*
134 * Condition variable attributes
135 */
136
137 /*
138 * Condition variables
139 */
140
141 #define PTHREAD_COND_INITIALIZER {_PTHREAD_COND_SIG_init}
142
143 /*
144 * Initialization control (once) variables
145 */
146
147 #define PTHREAD_ONCE_INIT {_PTHREAD_ONCE_SIG_init}
148
149 /*
150 * Thread Specific Data - keys
151 */
152
153 #include <sys/time.h>
154
155 /*
156 * Prototypes for all PTHREAD interfaces
157 */
158 int pthread_attr_destroy __P((pthread_attr_t *attr));
159 int pthread_attr_getdetachstate __P((const pthread_attr_t *attr,
160 int *detachstate));
161 int pthread_attr_getinheritsched __P((const pthread_attr_t *attr,
162 int *inheritsched));
163 int pthread_attr_getschedparam __P((const pthread_attr_t *attr,
164 struct sched_param *param));
165 int pthread_attr_getschedpolicy __P((const pthread_attr_t *attr,
166 int *policy));
167 int pthread_attr_getstackaddr __P((const pthread_attr_t *attr,
168 void **stackaddr));
169 int pthread_attr_getstacksize __P((const pthread_attr_t *attr,
170 size_t *stacksize));
171 int pthread_attr_init __P((pthread_attr_t *attr));
172 int pthread_attr_setdetachstate __P((pthread_attr_t *attr,
173 int detachstate));
174 int pthread_attr_setinheritsched __P((pthread_attr_t *attr,
175 int inheritsched));
176 int pthread_attr_setschedparam __P((pthread_attr_t *attr,
177 const struct sched_param *param));
178 int pthread_attr_setschedpolicy __P((pthread_attr_t *attr,
179 int policy));
180 int pthread_attr_setstackaddr __P((pthread_attr_t *attr,
181 void *stackaddr));
182 int pthread_attr_setstacksize __P((pthread_attr_t *attr,
183 size_t stacksize));
184 int pthread_cancel __P((pthread_t thread));
185 int pthread_setcancelstate __P((int state, int *oldstate));
186 int pthread_setcanceltype __P((int type, int *oldtype));
187 void pthread_testcancel __P((void));
188 int pthread_cond_broadcast __P((pthread_cond_t *cond));
189 int pthread_cond_destroy __P((pthread_cond_t *cond));
190 int pthread_cond_init __P((pthread_cond_t *cond,
191 const pthread_condattr_t *attr));
192 int pthread_cond_signal __P((pthread_cond_t *cond));
193 int pthread_cond_wait __P((pthread_cond_t *cond,
194 pthread_mutex_t *mutex));
195 int pthread_cond_timedwait __P((pthread_cond_t *cond,
196 pthread_mutex_t *mutex,
197 const struct timespec *abstime));
198 int pthread_cond_timedwait_relative_np __P((pthread_cond_t *cond,
199 pthread_mutex_t *mutex,
200 const struct timespec *reltime));
201 int pthread_create __P((pthread_t *thread,
202 const pthread_attr_t *attr,
203 void *(*start_routine)(void *),
204 void *arg));
205 int pthread_detach __P((pthread_t thread));
206 int pthread_equal __P((pthread_t t1,
207 pthread_t t2));
208 void pthread_exit __P((void *value_ptr));
209 int pthread_getschedparam __P((pthread_t thread,
210 int *policy,
211 struct sched_param *param));
212 int pthread_join __P((pthread_t thread,
213 void **value_ptr));
214 int pthread_mutex_destroy __P((pthread_mutex_t *mutex));
215 int pthread_mutex_getprioceiling __P((const pthread_mutex_t *mutex,
216 int *prioceiling));
217 int pthread_mutex_init __P((pthread_mutex_t *mutex,
218 const pthread_mutexattr_t *attr));
219 int pthread_mutex_lock __P((pthread_mutex_t *mutex));
220 int pthread_mutex_setprioceiling __P((pthread_mutex_t *mutex,
221 int prioceiling,
222 int *old_prioceiling));
223 int pthread_mutex_trylock __P((pthread_mutex_t *mutex));
224 int pthread_mutex_unlock __P((pthread_mutex_t *mutex));
225 int pthread_mutexattr_destroy __P((pthread_mutexattr_t *attr));
226 int pthread_mutexattr_getprioceiling __P((const pthread_mutexattr_t *attr,
227 int *prioceiling));
228 int pthread_mutexattr_getprotocol __P((const pthread_mutexattr_t *attr,
229 int *protocol));
230 int pthread_mutexattr_init __P((pthread_mutexattr_t *attr));
231 int pthread_mutexattr_setprioceiling __P((pthread_mutexattr_t *attr,
232 int prioceiling));
233 int pthread_mutexattr_setprotocol __P((pthread_mutexattr_t *attr,
234 int protocol));
235 int pthread_once __P((pthread_once_t *once_control,
236 void (*init_routine)(void)));
237 pthread_t pthread_self __P((void));
238 int pthread_setschedparam __P((pthread_t thread,
239 int policy,
240 const struct sched_param *param));
241 int pthread_key_create __P((pthread_key_t *key,
242 void (*destructor)(void *)));
243 int pthread_key_delete __P((pthread_key_t key));
244 int pthread_setspecific __P((pthread_key_t key,
245 const void *value));
246 void *pthread_getspecific __P((pthread_key_t key));
247 int pthread_attr_getscope __P((pthread_attr_t *, int *));
248 int pthread_attr_setscope __P((pthread_attr_t *, int));
249
250 /* returns non-zero if pthread_create or cthread_fork have been called */
251 int pthread_is_threaded_np __P((void));
252
253 /* return the mach thread bound to the pthread */
254 mach_port_t pthread_mach_thread_np __P((pthread_t));
255 size_t pthread_get_stacksize_np __P((pthread_t));
256 void * pthread_get_stackaddr_np __P((pthread_t));
257
258 /* Like pthread_cond_signal(), but only wake up the specified pthread */
259 int pthread_cond_signal_thread_np __P((pthread_cond_t *, pthread_t));
260
261 /* Like pthread_create(), but leaves the thread suspended */
262 int pthread_create_suspended_np __P((pthread_t *thread,
263 const pthread_attr_t *attr,
264 void *(*start_routine)(void *),
265 void *arg));
266 __END_DECLS
267 #endif /* _POSIX_PTHREAD_H */