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>
39 #include <mach/mach_types.h>
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:
49 * #ifdef _POSIX_THREADS
50 * #include <pthread.h>
55 /* These will be moved to unistd.h */
58 /* These two should be defined also */
59 #undef _POSIX_THREAD_PROCESS_SHARED
60 #undef _POSIX_THREAD_SAFE_FUNCTIONS
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>
68 #include <sys/cdefs.h>
77 * Cancel cleanup handler management. Note, since these are implemented as macros,
78 * they *MUST* occur in matched pairs!
81 #define pthread_cleanup_push(func, val) \
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;
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); \
100 #define PTHREAD_CREATE_JOINABLE 1
101 #define PTHREAD_CREATE_DETACHED 2
103 #define PTHREAD_INHERIT_SCHED 1
104 #define PTHREAD_EXPLICIT_SCHED 2
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 */
111 /* We only support PTHREAD_SCOPE_SYSTEM */
112 #define PTHREAD_SCOPE_SYSTEM 1
113 #define PTHREAD_SCOPE_PROCESS 2
115 /* Who defines this? */
117 #if !defined(ENOTSUP)
123 #define PTHREAD_PRIO_NONE 0
124 #define PTHREAD_PRIO_INHERIT 1
125 #define PTHREAD_PRIO_PROTECT 2
131 #define PTHREAD_MUTEX_INITIALIZER {_PTHREAD_MUTEX_SIG_init}
134 * Condition variable attributes
138 * Condition variables
141 #define PTHREAD_COND_INITIALIZER {_PTHREAD_COND_SIG_init}
144 * Initialization control (once) variables
147 #define PTHREAD_ONCE_INIT {_PTHREAD_ONCE_SIG_init}
150 * Thread Specific Data - keys
153 #include <sys/time.h>
156 * Prototypes for all PTHREAD interfaces
158 int pthread_attr_destroy
__P((pthread_attr_t
*attr
));
159 int pthread_attr_getdetachstate
__P((const pthread_attr_t
*attr
,
161 int pthread_attr_getinheritsched
__P((const pthread_attr_t
*attr
,
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
,
167 int pthread_attr_getstackaddr
__P((const pthread_attr_t
*attr
,
169 int pthread_attr_getstacksize
__P((const pthread_attr_t
*attr
,
171 int pthread_attr_init
__P((pthread_attr_t
*attr
));
172 int pthread_attr_setdetachstate
__P((pthread_attr_t
*attr
,
174 int pthread_attr_setinheritsched
__P((pthread_attr_t
*attr
,
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
,
180 int pthread_attr_setstackaddr
__P((pthread_attr_t
*attr
,
182 int pthread_attr_setstacksize
__P((pthread_attr_t
*attr
,
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 *),
205 int pthread_detach
__P((pthread_t thread
));
206 int pthread_equal
__P((pthread_t t1
,
208 void pthread_exit
__P((void *value_ptr
));
209 int pthread_getschedparam
__P((pthread_t thread
,
211 struct sched_param
*param
));
212 int pthread_join
__P((pthread_t thread
,
214 int pthread_mutex_destroy
__P((pthread_mutex_t
*mutex
));
215 int pthread_mutex_getprioceiling
__P((const pthread_mutex_t
*mutex
,
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
,
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
,
228 int pthread_mutexattr_getprotocol
__P((const pthread_mutexattr_t
*attr
,
230 int pthread_mutexattr_init
__P((pthread_mutexattr_t
*attr
));
231 int pthread_mutexattr_setprioceiling
__P((pthread_mutexattr_t
*attr
,
233 int pthread_mutexattr_setprotocol
__P((pthread_mutexattr_t
*attr
,
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
,
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
,
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));
250 /* returns non-zero if pthread_create or cthread_fork have been called */
251 int pthread_is_threaded_np
__P((void));
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
));
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
));
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 *),
267 #endif /* _POSIX_PTHREAD_H */