KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
pthread.h
Go to the documentation of this file.
1/* pthread.h
2 *
3 * Written by Joel Sherrill <joel@OARcorp.com>.
4 *
5 * COPYRIGHT (c) 1989-2000.
6 * On-Line Applications Research Corporation (OAR).
7 *
8 * Permission to use, copy, modify, and distribute this software for any
9 * purpose without fee is hereby granted, provided that this entire notice
10 * is included in all copies of any software which is or includes a copy
11 * or modification of this software.
12 *
13 * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
14 * WARRANTY. IN PARTICULAR, THE AUTHOR MAKES NO REPRESENTATION
15 * OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY OF THIS
16 * SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
17 *
18 */
19
20// Need a local copy of this because the default one is buggy.
21
22/** \file pthread.h
23 \brief POSIX-compatibile (sorta) threading support.
24 \ingroup threading_posix
25
26 This file was imported (with a few changes) from Newlib. If you really want
27 to know about the functions in here, you should probably consult the Single
28 Unix Specification and the POSIX specification. Here's a link to that:
29 http://pubs.opengroup.org/onlinepubs/007904875/basedefs/pthread.h.html
30
31 The rest of this file will remain undocumented, as it isn't really a part of
32 KOS proper... Also, doxygen tends to mangle this whole thing anyway...
33*/
34
35/** \cond */
36
37#ifndef __PTHREAD_h
38#define __PTHREAD_h
39
40#ifdef __cplusplus
41extern "C" {
42#endif
43
44#include <unistd.h>
45#include <sys/_pthread.h>
46
47#if defined(_POSIX_THREADS)
48
49#include <sys/types.h>
50#include <time.h>
51#include <sys/sched.h>
52
53 /* Register Fork Handlers, P1003.1c/Draft 10, P1003.1c/Draft 10, p. 27
54
55 If an OS does not support processes, then it falls under this provision
56 and may not provide pthread_atfork():
57
58 "Either the implementation shall support the pthread_atfork() function
59 as described above or the pthread_atfork() function shall not be
60 provided."
61
62 NOTE: RTEMS does not provide pthread_atfork(). */
63
64#if !defined(__rtems__)
65 int pthread_atfork(void (*prepare)(void), void (*parent)(void),
66 void (*child)(void));
67#endif
68
69 /* Mutex Initialization Attributes, P1003.1c/Draft 10, p. 81 */
70
71 int pthread_mutexattr_init(pthread_mutexattr_t *attr);
72 int pthread_mutexattr_destroy(pthread_mutexattr_t *attr);
73 int pthread_mutexattr_getpshared(const pthread_mutexattr_t *attr, int *pshared);
74 int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int pshared);
75
76 /* Initializing and Destroying a Mutex, P1003.1c/Draft 10, p. 87 */
77
78 int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr);
79 int pthread_mutex_destroy(pthread_mutex_t *mutex);
80
81 /* This is used to statically initialize a pthread_mutex_t. Example:
82
83 pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
84 */
85
86#define PTHREAD_MUTEX_INITIALIZER MUTEX_INITIALIZER
87
88 /* Locking and Unlocking a Mutex, P1003.1c/Draft 10, p. 93
89 NOTE: P1003.4b/D8 adds pthread_mutex_timedlock(), p. 29 */
90
91 int pthread_mutex_lock(pthread_mutex_t *mutex);
92 int pthread_mutex_trylock(pthread_mutex_t *mutex);
93 int pthread_mutex_unlock(pthread_mutex_t *mutex);
94
95#if defined(_POSIX_TIMEOUTS)
96
97 int pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *timeout);
98
99#endif /* _POSIX_TIMEOUTS */
100
101 /* Condition Variable Initialization Attributes, P1003.1c/Draft 10, p. 96 */
102
103 int pthread_condattr_init(pthread_condattr_t *attr);
104 int pthread_condattr_destroy(pthread_condattr_t *attr);
105 int pthread_condattr_getpshared(const pthread_condattr_t *attr, int *pshared);
106 int pthread_condattr_setpshared(pthread_condattr_t *attr, int pshared);
107
108 /* Initializing and Destroying a Condition Variable, P1003.1c/Draft 10, p. 87 */
109
110 int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr);
111 int pthread_cond_destroy(pthread_cond_t *cond);
112
113 /* This is used to statically initialize a pthread_cond_t. Example:
114
115 pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
116 */
117
118#define PTHREAD_COND_INITIALIZER COND_INITIALIZER
119
120 /* Broadcasting and Signaling a Condition, P1003.1c/Draft 10, p. 101 */
121
122 int pthread_cond_signal(pthread_cond_t *cond);
123 int pthread_cond_broadcast(pthread_cond_t *cond);
124
125 /* Waiting on a Condition, P1003.1c/Draft 10, p. 105 */
126
127 int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex);
128
129 int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
130 const struct timespec *abstime);
131
132#if defined(_POSIX_THREAD_PRIORITY_SCHEDULING)
133
134 /* Thread Creation Scheduling Attributes, P1003.1c/Draft 10, p. 120 */
135
136 int pthread_attr_setscope(pthread_attr_t *attr, int contentionscope);
137 int pthread_attr_getscope(const pthread_attr_t *attr, int *contentionscope);
138 int pthread_attr_setinheritsched(pthread_attr_t *attr, int inheritsched);
139 int pthread_attr_getinheritsched(const pthread_attr_t *attr, int *inheritsched);
140 int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy);
141 int pthread_attr_getschedpolicy(const pthread_attr_t *attr, int *policy);
142
143#endif /* defined(_POSIX_THREAD_PRIORITY_SCHEDULING) */
144
145 int pthread_attr_setschedparam(pthread_attr_t *attr, const struct sched_param *param);
146 int pthread_attr_getschedparam(const pthread_attr_t *attr, struct sched_param *param);
147
148#if defined(_POSIX_THREAD_PRIORITY_SCHEDULING)
149
150 /* Dynamic Thread Scheduling Parameters Access, P1003.1c/Draft 10, p. 124 */
151
152 int pthread_getschedparam(pthread_t thread, int *policy, struct sched_param *param);
153 int pthread_setschedparam(pthread_t thread, int policy, struct sched_param *param);
154
155#endif /* defined(_POSIX_THREAD_PRIORITY_SCHEDULING) */
156
157#if defined(_POSIX_THREAD_PRIO_INHERIT) || defined(_POSIX_THREAD_PRIO_PROTECT)
158
159 /* Mutex Initialization Scheduling Attributes, P1003.1c/Draft 10, p. 128 */
160
161 int pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr, int protocol);
162 int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *attr, int *protocol);
163 int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *attr, int prioceiling);
164 int pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *attr, int *prioceiling);
165
166#endif /* _POSIX_THREAD_PRIO_INHERIT || _POSIX_THREAD_PRIO_PROTECT */
167
168#if defined(_POSIX_THREAD_PRIO_PROTECT)
169
170 /* Change the Priority Ceiling of a Mutex, P1003.1c/Draft 10, p. 131 */
171
172 int pthread_mutex_setprioceiling(pthread_mutex_t *mutex, int prioceiling, int *old_ceiling);
173 int pthread_mutex_getprioceiling(pthread_mutex_t *mutex, int *prioceiling);
174
175#endif /* _POSIX_THREAD_PRIO_PROTECT */
176
177 /* Thread Creation Attributes, P1003.1c/Draft 10, p, 140 */
178
179 int pthread_attr_init(pthread_attr_t *attr);
180 int pthread_attr_destroy(pthread_attr_t *attr);
181 int pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize);
182 int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize);
183 int pthread_attr_getstackaddr(const pthread_attr_t *attr, void **stackaddr);
184 int pthread_attr_setstackaddr(pthread_attr_t *attr, void *stackaddr);
185 int pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate);
186 int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate);
187
188 /* Thread Creation, P1003.1c/Draft 10, p. 144 */
189
190 int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
191 void * (*start_routine)(void *), void *arg);
192
193 /* Wait for Thread Termination, P1003.1c/Draft 10, p. 147 */
194
195 int pthread_join(pthread_t thread, void **value_ptr);
196
197 /* Detaching a Thread, P1003.1c/Draft 10, p. 149 */
198
199 int pthread_detach(pthread_t thread);
200
201 /* Thread Termination, p1003.1c/Draft 10, p. 150 */
202
203 void pthread_exit(void *value_ptr);
204
205 /* Get Calling Thread's ID, p1003.1c/Draft 10, p. XXX */
206
207 pthread_t pthread_self(void);
208
209 /* Compare Thread IDs, p1003.1c/Draft 10, p. 153 */
210
211 int pthread_equal(pthread_t t1, pthread_t t2);
212
213 /* Dynamic Package Initialization */
214
215 /* This is used to statically initialize a pthread_once_t. Example:
216
217 pthread_once_t once = PTHREAD_ONCE_INIT;
218
219 NOTE: This is named inconsistently -- it should be INITIALIZER. */
220
221#define PTHREAD_ONCE_INIT { 1, 0 } /* is initialized and not run */
222
223 int pthread_once(pthread_once_t *once_control, void (*init_routine)(void));
224
225 /* Thread-Specific Data Key Create, P1003.1c/Draft 10, p. 163 */
226
227 int pthread_key_create(pthread_key_t *key, void (*destructor)(void *));
228
229 /* Thread-Specific Data Management, P1003.1c/Draft 10, p. 165 */
230
231 int pthread_setspecific(pthread_key_t key, const void *value);
232 void *pthread_getspecific(pthread_key_t key);
233
234 /* Thread-Specific Data Key Deletion, P1003.1c/Draft 10, p. 167 */
235
236 int pthread_key_delete(pthread_key_t key);
237
238 /* Execution of a Thread, P1003.1c/Draft 10, p. 181 */
239
240#define PTHREAD_CANCEL_ENABLE 0
241#define PTHREAD_CANCEL_DISABLE 1
242
243#define PTHREAD_CANCEL_DEFERRED 0
244#define PTHREAD_CANCEL_ASYNCHRONOUS 1
245
246#define PTHREAD_CANCELED ((void *) -1)
247
248 int pthread_cancel(pthread_t thread);
249
250 /* Setting Cancelability State, P1003.1c/Draft 10, p. 183 */
251
252 int pthread_setcancelstate(int state, int *oldstate);
253 int pthread_setcanceltype(int type, int *oldtype);
254 void pthread_testcancel(void);
255
256 /* Establishing Cancellation Handlers, P1003.1c/Draft 10, p. 184 */
257
258 void pthread_cleanup_push(void (*routine)(void *), void *arg);
259 void pthread_cleanup_pop(int execute);
260
261#if defined(_POSIX_THREAD_CPUTIME)
262
263 /* Accessing a Thread CPU-time Clock, P1003.4b/D8, p. 58 */
264
265 int pthread_getcpuclockid(pthread_t thread_id, clockid_t *clock_id);
266
267 /* CPU-time Clock Thread Creation Attribute, P1003.4b/D8, p. 59 */
268
269 int pthread_attr_setcputime(pthread_attr_t *attr, int clock_allowed);
270
271 int pthread_attr_getcputime(pthread_attr_t *attr, int *clock_allowed);
272
273#endif /* defined(_POSIX_THREAD_CPUTIME) */
274
275#endif /* defined(_POSIX_THREADS) */
276
277#ifdef __cplusplus
278}
279#endif
280
281#endif
282/** \endcond */
283/* end of include file */
Basic sys/_pthread.h file for newlib.
Basic sys/sched.h file for newlib.
kthread_key_t pthread_key_t
POSIX thread data key.
Definition sched.h:74
kthread_once_t pthread_once_t
POSIX once control.
Definition sched.h:73
Condition variable.
Definition cond.h:62
Structure describing one running thread.
Definition thread.h:169
Mutual exclusion lock type.
Definition mutex.h:68
POSIX thread attributes.
Definition sched.h:62
POSIX condition variable attributes.
Definition sched.h:52
POSIX mutex attributes.
Definition sched.h:42
Scheduling Parameters, P1003.1b-1993, p.
Definition sched.h:23
KOS-implementation of select C11 and POSIX extensions.