2 * Copyright 1996 1995 by Open Software Foundation, Inc. 1997 1996 1995 1994 1993 1992 1991
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.
11 * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
12 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
13 * FOR A PARTICULAR PURPOSE.
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.
27 * POSIX Threads - IEEE 1003.1c
30 #ifndef _POSIX_PTHREAD_H
31 #define _POSIX_PTHREAD_H
34 #include <pthread_impl.h>
43 #ifndef _POSIX_C_SOURCE
44 #include <mach/mach_types.h>
45 #endif /* ! _POSIX_C_SOURCE */
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:
53 * #ifdef _POSIX_THREADS
54 * #include <pthread.h>
59 /* These will be moved to unistd.h */
62 /* These two should be defined also */
63 #undef _POSIX_THREAD_PROCESS_SHARED
64 #undef _POSIX_THREAD_SAFE_FUNCTIONS
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>
72 #include <sys/cdefs.h>
81 * Cancel cleanup handler management. Note, since these are implemented as macros,
82 * they *MUST* occur in matched pairs!
85 #define pthread_cleanup_push(func, val) \
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;
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); \
104 #define PTHREAD_CREATE_JOINABLE 1
105 #define PTHREAD_CREATE_DETACHED 2
107 #define PTHREAD_INHERIT_SCHED 1
108 #define PTHREAD_EXPLICIT_SCHED 2
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 */
115 /* We only support PTHREAD_SCOPE_SYSTEM */
116 #define PTHREAD_SCOPE_SYSTEM 1
117 #define PTHREAD_SCOPE_PROCESS 2
119 /* We only support PTHREAD_PROCESS_PRIVATE */
120 #define PTHREAD_PROCESS_SHARED 1
121 #define PTHREAD_PROCESS_PRIVATE 2
123 /* Who defines this? */
125 #if !defined(ENOTSUP)
129 * Mutex protocol attributes
131 #define PTHREAD_PRIO_NONE 0
132 #define PTHREAD_PRIO_INHERIT 1
133 #define PTHREAD_PRIO_PROTECT 2
136 * Mutex type attributes
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
146 #define PTHREAD_MUTEX_INITIALIZER {_PTHREAD_MUTEX_SIG_init, {}}
149 * Condition variable attributes
153 * Condition variables
156 #define PTHREAD_COND_INITIALIZER {_PTHREAD_COND_SIG_init, {}}
159 * Initialization control (once) variables
162 #define PTHREAD_ONCE_INIT {_PTHREAD_ONCE_SIG_init, {}}
165 * Thread Specific Data - keys
168 #include <sys/time.h>
171 * Prototypes for all PTHREAD interfaces
173 int pthread_attr_destroy
__P((pthread_attr_t
*attr
));
174 int pthread_attr_getdetachstate
__P((const pthread_attr_t
*attr
,
176 int pthread_attr_getinheritsched
__P((const pthread_attr_t
*attr
,
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
,
182 int pthread_attr_getstackaddr
__P((const pthread_attr_t
*attr
,
184 int pthread_attr_getstacksize
__P((const pthread_attr_t
*attr
,
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
,
191 int pthread_attr_setinheritsched
__P((pthread_attr_t
*attr
,
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
,
197 int pthread_attr_setstackaddr
__P((pthread_attr_t
*attr
,
199 int pthread_attr_setstacksize
__P((pthread_attr_t
*attr
,
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
,
221 int pthread_condattr_setpshared
__P((pthread_condattr_t
*attr
,
223 int pthread_create
__P((pthread_t
*thread
,
224 const pthread_attr_t
*attr
,
225 void *(*start_routine
)(void *),
227 int pthread_detach
__P((pthread_t thread
));
228 int pthread_equal
__P((pthread_t t1
,
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
,
236 struct sched_param
*param
));
237 int pthread_join
__P((pthread_t thread
,
239 int pthread_mutex_destroy
__P((pthread_mutex_t
*mutex
));
240 int pthread_mutex_getprioceiling
__P((const pthread_mutex_t
*mutex
,
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
,
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
,
253 int pthread_mutexattr_getprotocol
__P((const pthread_mutexattr_t
*attr
,
255 int pthread_mutexattr_getpshared
__P((const pthread_mutexattr_t
*attr
,
257 int pthread_mutexattr_gettype
__P((const pthread_mutexattr_t
*attr
,
259 int pthread_mutexattr_init
__P((pthread_mutexattr_t
*attr
));
260 int pthread_mutexattr_setprioceiling
__P((pthread_mutexattr_t
*attr
,
262 int pthread_mutexattr_setprotocol
__P((pthread_mutexattr_t
*attr
,
264 int pthread_mutexattr_settype
__P((pthread_mutexattr_t
*attr
,
266 int pthread_mutexattr_setpshared
__P((pthread_mutexattr_t
*attr
,
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
,
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
,
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
,
296 int pthread_rwlockattr_setpshared
__P((pthread_rwlockattr_t
*attr
,
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));
303 /* returns non-zero if the current thread is the main thread */
304 int pthread_main_np
__P((void));
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
));
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
));
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
));
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 *),
324 void pthread_yield_np
__P((void));
325 #endif /* ! _POSIX_C_SOURCE */
327 #endif /* _POSIX_PTHREAD_H */