]>
Commit | Line | Data |
---|---|---|
568035b7 | 1 | /* Copyright (C) 2002-2013 Free Software Foundation, Inc. |
76a50749 UD |
2 | This file is part of the GNU C Library. |
3 | ||
4 | The GNU C Library is free software; you can redistribute it and/or | |
5 | modify it under the terms of the GNU Lesser General Public | |
6 | License as published by the Free Software Foundation; either | |
7 | version 2.1 of the License, or (at your option) any later version. | |
8 | ||
9 | The GNU C Library is distributed in the hope that it will be useful, | |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 | Lesser General Public License for more details. | |
13 | ||
14 | You should have received a copy of the GNU Lesser General Public | |
59ba27a6 PE |
15 | License along with the GNU C Library; if not, see |
16 | <http://www.gnu.org/licenses/>. */ | |
76a50749 UD |
17 | |
18 | #ifndef _PTHREAD_H | |
19 | #define _PTHREAD_H 1 | |
20 | ||
21 | #include <features.h> | |
e59660bc | 22 | #include <endian.h> |
76a50749 UD |
23 | #include <sched.h> |
24 | #include <time.h> | |
25 | ||
76a50749 | 26 | #include <bits/pthreadtypes.h> |
09d65ff3 | 27 | #include <bits/setjmp.h> |
31f93b3b | 28 | #include <bits/wordsize.h> |
76a50749 UD |
29 | |
30 | ||
31 | /* Detach state. */ | |
32 | enum | |
33 | { | |
34 | PTHREAD_CREATE_JOINABLE, | |
35 | #define PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_JOINABLE | |
36 | PTHREAD_CREATE_DETACHED | |
37 | #define PTHREAD_CREATE_DETACHED PTHREAD_CREATE_DETACHED | |
38 | }; | |
39 | ||
40 | ||
a1ea4c06 | 41 | /* Mutex types. */ |
76a50749 UD |
42 | enum |
43 | { | |
44 | PTHREAD_MUTEX_TIMED_NP, | |
45 | PTHREAD_MUTEX_RECURSIVE_NP, | |
46 | PTHREAD_MUTEX_ERRORCHECK_NP, | |
47 | PTHREAD_MUTEX_ADAPTIVE_NP | |
d3c7e686 | 48 | #if defined __USE_UNIX98 || defined __USE_XOPEN2K8 |
76a50749 UD |
49 | , |
50 | PTHREAD_MUTEX_NORMAL = PTHREAD_MUTEX_TIMED_NP, | |
51 | PTHREAD_MUTEX_RECURSIVE = PTHREAD_MUTEX_RECURSIVE_NP, | |
52 | PTHREAD_MUTEX_ERRORCHECK = PTHREAD_MUTEX_ERRORCHECK_NP, | |
53 | PTHREAD_MUTEX_DEFAULT = PTHREAD_MUTEX_NORMAL | |
54 | #endif | |
55 | #ifdef __USE_GNU | |
56 | /* For compatibility. */ | |
57 | , PTHREAD_MUTEX_FAST_NP = PTHREAD_MUTEX_TIMED_NP | |
58 | #endif | |
59 | }; | |
60 | ||
1bcfb5a5 | 61 | |
77db439e | 62 | #ifdef __USE_XOPEN2K |
1bcfb5a5 UD |
63 | /* Robust mutex or not flags. */ |
64 | enum | |
65 | { | |
77db439e UD |
66 | PTHREAD_MUTEX_STALLED, |
67 | PTHREAD_MUTEX_STALLED_NP = PTHREAD_MUTEX_STALLED, | |
1f04d005 | 68 | PTHREAD_MUTEX_ROBUST, |
77db439e | 69 | PTHREAD_MUTEX_ROBUST_NP = PTHREAD_MUTEX_ROBUST |
1bcfb5a5 UD |
70 | }; |
71 | #endif | |
72 | ||
73 | ||
4efeffc1 | 74 | #if defined __USE_POSIX199506 || defined __USE_UNIX98 |
a5f2bd86 RM |
75 | /* Mutex protocols. */ |
76 | enum | |
77 | { | |
78 | PTHREAD_PRIO_NONE, | |
79 | PTHREAD_PRIO_INHERIT, | |
80 | PTHREAD_PRIO_PROTECT | |
81 | }; | |
82 | #endif | |
83 | ||
84 | ||
1bcfb5a5 | 85 | /* Mutex initializers. */ |
b023e4ca AK |
86 | #if __PTHREAD_MUTEX_HAVE_ELISION == 1 /* 64bit layout. */ |
87 | #define __PTHREAD_SPINS 0, 0 | |
88 | #elif __PTHREAD_MUTEX_HAVE_ELISION == 2 /* 32bit layout. */ | |
89 | #define __PTHREAD_SPINS { 0, 0 } | |
90 | #else | |
91 | #define __PTHREAD_SPINS 0 | |
92 | #endif | |
93 | ||
1f59b0b1 | 94 | #ifdef __PTHREAD_MUTEX_HAVE_PREV |
1bcfb5a5 | 95 | # define PTHREAD_MUTEX_INITIALIZER \ |
b023e4ca | 96 | { { 0, 0, 0, 0, 0, __PTHREAD_SPINS, { 0, 0 } } } |
1bcfb5a5 | 97 | # ifdef __USE_GNU |
31f93b3b | 98 | # define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \ |
b023e4ca | 99 | { { 0, 0, 0, 0, PTHREAD_MUTEX_RECURSIVE_NP, __PTHREAD_SPINS, { 0, 0 } } } |
31f93b3b | 100 | # define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \ |
b023e4ca | 101 | { { 0, 0, 0, 0, PTHREAD_MUTEX_ERRORCHECK_NP, __PTHREAD_SPINS, { 0, 0 } } } |
31f93b3b | 102 | # define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP \ |
b023e4ca AK |
103 | { { 0, 0, 0, 0, PTHREAD_MUTEX_ADAPTIVE_NP, __PTHREAD_SPINS, { 0, 0 } } } |
104 | # define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP \ | |
105 | { { 0, 0, 0, 0, PTHREAD_MUTEX_ADAPTIVE_NP, __PTHREAD_SPINS, { 0, 0 } } } | |
106 | ||
1bcfb5a5 UD |
107 | # endif |
108 | #else | |
109 | # define PTHREAD_MUTEX_INITIALIZER \ | |
b023e4ca | 110 | { { 0, 0, 0, 0, 0, { __PTHREAD_SPINS } } } |
1bcfb5a5 | 111 | # ifdef __USE_GNU |
31f93b3b | 112 | # define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \ |
b023e4ca | 113 | { { 0, 0, 0, PTHREAD_MUTEX_RECURSIVE_NP, 0, { __PTHREAD_SPINS } } } |
31f93b3b | 114 | # define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \ |
b023e4ca | 115 | { { 0, 0, 0, PTHREAD_MUTEX_ERRORCHECK_NP, 0, { __PTHREAD_SPINS } } } |
31f93b3b | 116 | # define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP \ |
b023e4ca AK |
117 | { { 0, 0, 0, PTHREAD_MUTEX_ADAPTIVE_NP, 0, { __PTHREAD_SPINS } } } |
118 | ||
31f93b3b | 119 | # endif |
a1ea4c06 UD |
120 | #endif |
121 | ||
76a50749 UD |
122 | |
123 | /* Read-write lock types. */ | |
20f8e666 | 124 | #if defined __USE_UNIX98 || defined __USE_XOPEN2K |
76a50749 UD |
125 | enum |
126 | { | |
127 | PTHREAD_RWLOCK_PREFER_READER_NP, | |
128 | PTHREAD_RWLOCK_PREFER_WRITER_NP, | |
129 | PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP, | |
130 | PTHREAD_RWLOCK_DEFAULT_NP = PTHREAD_RWLOCK_PREFER_READER_NP | |
131 | }; | |
76a50749 | 132 | |
245a11d7 L |
133 | /* Define __PTHREAD_RWLOCK_INT_FLAGS_SHARED to 1 if pthread_rwlock_t |
134 | has the shared field. All 64-bit architectures have the shared field | |
135 | in pthread_rwlock_t. */ | |
136 | #ifndef __PTHREAD_RWLOCK_INT_FLAGS_SHARED | |
137 | # if __WORDSIZE == 64 | |
138 | # define __PTHREAD_RWLOCK_INT_FLAGS_SHARED 1 | |
139 | # endif | |
140 | #endif | |
141 | ||
a1ea4c06 | 142 | /* Read-write lock initializers. */ |
e59660bc | 143 | # define PTHREAD_RWLOCK_INITIALIZER \ |
5a337776 | 144 | { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } } |
20f8e666 | 145 | # ifdef __USE_GNU |
245a11d7 | 146 | # ifdef __PTHREAD_RWLOCK_INT_FLAGS_SHARED |
20f8e666 | 147 | # define PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP \ |
31f93b3b | 148 | { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ |
5a337776 | 149 | PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP } } |
20f8e666 | 150 | # else |
e59660bc UD |
151 | # if __BYTE_ORDER == __LITTLE_ENDIAN |
152 | # define PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP \ | |
153 | { { 0, 0, 0, 0, 0, 0, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP, \ | |
154 | 0, 0, 0, 0 } } | |
155 | # else | |
156 | # define PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP \ | |
157 | { { 0, 0, 0, 0, 0, 0, 0, 0, 0, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP,\ | |
158 | 0 } } | |
159 | # endif | |
20f8e666 | 160 | # endif |
31f93b3b | 161 | # endif |
20f8e666 | 162 | #endif /* Unix98 or XOpen2K */ |
a1ea4c06 | 163 | |
76a50749 UD |
164 | |
165 | /* Scheduler inheritance. */ | |
166 | enum | |
167 | { | |
168 | PTHREAD_INHERIT_SCHED, | |
169 | #define PTHREAD_INHERIT_SCHED PTHREAD_INHERIT_SCHED | |
170 | PTHREAD_EXPLICIT_SCHED | |
171 | #define PTHREAD_EXPLICIT_SCHED PTHREAD_EXPLICIT_SCHED | |
172 | }; | |
173 | ||
174 | ||
175 | /* Scope handling. */ | |
176 | enum | |
177 | { | |
178 | PTHREAD_SCOPE_SYSTEM, | |
179 | #define PTHREAD_SCOPE_SYSTEM PTHREAD_SCOPE_SYSTEM | |
180 | PTHREAD_SCOPE_PROCESS | |
181 | #define PTHREAD_SCOPE_PROCESS PTHREAD_SCOPE_PROCESS | |
182 | }; | |
183 | ||
184 | ||
185 | /* Process shared or private flag. */ | |
186 | enum | |
187 | { | |
188 | PTHREAD_PROCESS_PRIVATE, | |
189 | #define PTHREAD_PROCESS_PRIVATE PTHREAD_PROCESS_PRIVATE | |
190 | PTHREAD_PROCESS_SHARED | |
191 | #define PTHREAD_PROCESS_SHARED PTHREAD_PROCESS_SHARED | |
192 | }; | |
193 | ||
194 | ||
195 | ||
196 | /* Conditional variable handling. */ | |
3fd1bc67 | 197 | #define PTHREAD_COND_INITIALIZER { { 0, 0, 0, 0, 0, (void *) 0, 0, 0 } } |
76a50749 UD |
198 | |
199 | ||
200 | /* Cleanup buffers */ | |
201 | struct _pthread_cleanup_buffer | |
202 | { | |
203 | void (*__routine) (void *); /* Function to call. */ | |
204 | void *__arg; /* Its argument. */ | |
205 | int __canceltype; /* Saved cancellation type. */ | |
206 | struct _pthread_cleanup_buffer *__prev; /* Chaining of cleanup functions. */ | |
207 | }; | |
208 | ||
209 | /* Cancellation */ | |
210 | enum | |
211 | { | |
212 | PTHREAD_CANCEL_ENABLE, | |
213 | #define PTHREAD_CANCEL_ENABLE PTHREAD_CANCEL_ENABLE | |
214 | PTHREAD_CANCEL_DISABLE | |
215 | #define PTHREAD_CANCEL_DISABLE PTHREAD_CANCEL_DISABLE | |
216 | }; | |
217 | enum | |
218 | { | |
219 | PTHREAD_CANCEL_DEFERRED, | |
220 | #define PTHREAD_CANCEL_DEFERRED PTHREAD_CANCEL_DEFERRED | |
221 | PTHREAD_CANCEL_ASYNCHRONOUS | |
222 | #define PTHREAD_CANCEL_ASYNCHRONOUS PTHREAD_CANCEL_ASYNCHRONOUS | |
223 | }; | |
224 | #define PTHREAD_CANCELED ((void *) -1) | |
225 | ||
226 | ||
227 | /* Single execution handling. */ | |
228 | #define PTHREAD_ONCE_INIT 0 | |
229 | ||
230 | ||
231 | #ifdef __USE_XOPEN2K | |
232 | /* Value returned by 'pthread_barrier_wait' for one of the threads after | |
233 | the required number of threads have called this function. | |
234 | -1 is distinct from 0 and all errno constants */ | |
235 | # define PTHREAD_BARRIER_SERIAL_THREAD -1 | |
236 | #endif | |
237 | ||
238 | ||
239 | __BEGIN_DECLS | |
240 | ||
241 | /* Create a new thread, starting with execution of START-ROUTINE | |
242 | getting passed ARG. Creation attributed come from ATTR. The new | |
243 | handle is stored in *NEWTHREAD. */ | |
244 | extern int pthread_create (pthread_t *__restrict __newthread, | |
a784e502 | 245 | const pthread_attr_t *__restrict __attr, |
76a50749 | 246 | void *(*__start_routine) (void *), |
3871f58f | 247 | void *__restrict __arg) __THROWNL __nonnull ((1, 3)); |
76a50749 | 248 | |
68b9e1ae UD |
249 | /* Terminate calling thread. |
250 | ||
251 | The registered cleanup handlers are called via exception handling | |
252 | so we cannot mark this function with __THROW.*/ | |
253 | extern void pthread_exit (void *__retval) __attribute__ ((__noreturn__)); | |
76a50749 UD |
254 | |
255 | /* Make calling thread wait for termination of the thread TH. The | |
256 | exit status of the thread is stored in *THREAD_RETURN, if THREAD_RETURN | |
4e648ea3 UD |
257 | is not NULL. |
258 | ||
259 | This function is a cancellation point and therefore not marked with | |
260 | __THROW. */ | |
261 | extern int pthread_join (pthread_t __th, void **__thread_return); | |
76a50749 UD |
262 | |
263 | #ifdef __USE_GNU | |
264 | /* Check whether thread TH has terminated. If yes return the status of | |
265 | the thread in *THREAD_RETURN, if THREAD_RETURN is not NULL. */ | |
266 | extern int pthread_tryjoin_np (pthread_t __th, void **__thread_return) __THROW; | |
267 | ||
268 | /* Make calling thread wait for termination of the thread TH, but only | |
269 | until TIMEOUT. The exit status of the thread is stored in | |
4e648ea3 UD |
270 | *THREAD_RETURN, if THREAD_RETURN is not NULL. |
271 | ||
272 | This function is a cancellation point and therefore not marked with | |
273 | __THROW. */ | |
76a50749 | 274 | extern int pthread_timedjoin_np (pthread_t __th, void **__thread_return, |
a784e502 | 275 | const struct timespec *__abstime); |
76a50749 UD |
276 | #endif |
277 | ||
278 | /* Indicate that the thread TH is never to be joined with PTHREAD_JOIN. | |
279 | The resources of TH will therefore be freed immediately when it | |
280 | terminates, instead of waiting for another thread to perform PTHREAD_JOIN | |
281 | on it. */ | |
282 | extern int pthread_detach (pthread_t __th) __THROW; | |
283 | ||
284 | ||
285 | /* Obtain the identifier of the current thread. */ | |
286 | extern pthread_t pthread_self (void) __THROW __attribute__ ((__const__)); | |
287 | ||
288 | /* Compare two thread identifiers. */ | |
8898f020 UD |
289 | extern int pthread_equal (pthread_t __thread1, pthread_t __thread2) |
290 | __THROW __attribute__ ((__const__)); | |
76a50749 UD |
291 | |
292 | ||
293 | /* Thread attribute handling. */ | |
294 | ||
295 | /* Initialize thread attribute *ATTR with default attributes | |
296 | (detachstate is PTHREAD_JOINABLE, scheduling policy is SCHED_OTHER, | |
297 | no user-provided stack). */ | |
feb37183 | 298 | extern int pthread_attr_init (pthread_attr_t *__attr) __THROW __nonnull ((1)); |
76a50749 UD |
299 | |
300 | /* Destroy thread attribute *ATTR. */ | |
feb37183 UD |
301 | extern int pthread_attr_destroy (pthread_attr_t *__attr) |
302 | __THROW __nonnull ((1)); | |
76a50749 UD |
303 | |
304 | /* Get detach state attribute. */ | |
a784e502 | 305 | extern int pthread_attr_getdetachstate (const pthread_attr_t *__attr, |
feb37183 UD |
306 | int *__detachstate) |
307 | __THROW __nonnull ((1, 2)); | |
76a50749 UD |
308 | |
309 | /* Set detach state attribute. */ | |
310 | extern int pthread_attr_setdetachstate (pthread_attr_t *__attr, | |
feb37183 UD |
311 | int __detachstate) |
312 | __THROW __nonnull ((1)); | |
76a50749 UD |
313 | |
314 | ||
315 | /* Get the size of the guard area created for stack overflow protection. */ | |
a784e502 | 316 | extern int pthread_attr_getguardsize (const pthread_attr_t *__attr, |
feb37183 UD |
317 | size_t *__guardsize) |
318 | __THROW __nonnull ((1, 2)); | |
76a50749 UD |
319 | |
320 | /* Set the size of the guard area created for stack overflow protection. */ | |
321 | extern int pthread_attr_setguardsize (pthread_attr_t *__attr, | |
feb37183 UD |
322 | size_t __guardsize) |
323 | __THROW __nonnull ((1)); | |
76a50749 UD |
324 | |
325 | ||
326 | /* Return in *PARAM the scheduling parameters of *ATTR. */ | |
a784e502 | 327 | extern int pthread_attr_getschedparam (const pthread_attr_t *__restrict __attr, |
76a50749 | 328 | struct sched_param *__restrict __param) |
feb37183 | 329 | __THROW __nonnull ((1, 2)); |
76a50749 UD |
330 | |
331 | /* Set scheduling parameters (priority, etc) in *ATTR according to PARAM. */ | |
332 | extern int pthread_attr_setschedparam (pthread_attr_t *__restrict __attr, | |
a784e502 | 333 | const struct sched_param *__restrict |
feb37183 | 334 | __param) __THROW __nonnull ((1, 2)); |
76a50749 UD |
335 | |
336 | /* Return in *POLICY the scheduling policy of *ATTR. */ | |
a784e502 | 337 | extern int pthread_attr_getschedpolicy (const pthread_attr_t *__restrict |
76a50749 | 338 | __attr, int *__restrict __policy) |
feb37183 | 339 | __THROW __nonnull ((1, 2)); |
76a50749 UD |
340 | |
341 | /* Set scheduling policy in *ATTR according to POLICY. */ | |
342 | extern int pthread_attr_setschedpolicy (pthread_attr_t *__attr, int __policy) | |
feb37183 | 343 | __THROW __nonnull ((1)); |
76a50749 UD |
344 | |
345 | /* Return in *INHERIT the scheduling inheritance mode of *ATTR. */ | |
a784e502 | 346 | extern int pthread_attr_getinheritsched (const pthread_attr_t *__restrict |
76a50749 | 347 | __attr, int *__restrict __inherit) |
feb37183 | 348 | __THROW __nonnull ((1, 2)); |
76a50749 UD |
349 | |
350 | /* Set scheduling inheritance mode in *ATTR according to INHERIT. */ | |
351 | extern int pthread_attr_setinheritsched (pthread_attr_t *__attr, | |
feb37183 UD |
352 | int __inherit) |
353 | __THROW __nonnull ((1)); | |
76a50749 UD |
354 | |
355 | ||
356 | /* Return in *SCOPE the scheduling contention scope of *ATTR. */ | |
a784e502 | 357 | extern int pthread_attr_getscope (const pthread_attr_t *__restrict __attr, |
feb37183 UD |
358 | int *__restrict __scope) |
359 | __THROW __nonnull ((1, 2)); | |
76a50749 UD |
360 | |
361 | /* Set scheduling contention scope in *ATTR according to SCOPE. */ | |
362 | extern int pthread_attr_setscope (pthread_attr_t *__attr, int __scope) | |
feb37183 | 363 | __THROW __nonnull ((1)); |
76a50749 UD |
364 | |
365 | /* Return the previously set address for the stack. */ | |
a784e502 | 366 | extern int pthread_attr_getstackaddr (const pthread_attr_t *__restrict |
76a50749 | 367 | __attr, void **__restrict __stackaddr) |
feb37183 | 368 | __THROW __nonnull ((1, 2)) __attribute_deprecated__; |
76a50749 UD |
369 | |
370 | /* Set the starting address of the stack of the thread to be created. | |
371 | Depending on whether the stack grows up or down the value must either | |
372 | be higher or lower than all the address in the memory block. The | |
973d66e4 | 373 | minimal size of the block must be PTHREAD_STACK_MIN. */ |
76a50749 | 374 | extern int pthread_attr_setstackaddr (pthread_attr_t *__attr, |
3b7ed871 | 375 | void *__stackaddr) |
feb37183 | 376 | __THROW __nonnull ((1)) __attribute_deprecated__; |
76a50749 UD |
377 | |
378 | /* Return the currently used minimal stack size. */ | |
a784e502 | 379 | extern int pthread_attr_getstacksize (const pthread_attr_t *__restrict |
76a50749 | 380 | __attr, size_t *__restrict __stacksize) |
feb37183 | 381 | __THROW __nonnull ((1, 2)); |
76a50749 UD |
382 | |
383 | /* Add information about the minimum stack size needed for the thread | |
973d66e4 | 384 | to be started. This size must never be less than PTHREAD_STACK_MIN |
76a50749 UD |
385 | and must also not exceed the system limits. */ |
386 | extern int pthread_attr_setstacksize (pthread_attr_t *__attr, | |
feb37183 UD |
387 | size_t __stacksize) |
388 | __THROW __nonnull ((1)); | |
76a50749 UD |
389 | |
390 | #ifdef __USE_XOPEN2K | |
391 | /* Return the previously set address for the stack. */ | |
a784e502 | 392 | extern int pthread_attr_getstack (const pthread_attr_t *__restrict __attr, |
76a50749 | 393 | void **__restrict __stackaddr, |
feb37183 UD |
394 | size_t *__restrict __stacksize) |
395 | __THROW __nonnull ((1, 2, 3)); | |
76a50749 UD |
396 | |
397 | /* The following two interfaces are intended to replace the last two. They | |
398 | require setting the address as well as the size since only setting the | |
399 | address will make the implementation on some architectures impossible. */ | |
400 | extern int pthread_attr_setstack (pthread_attr_t *__attr, void *__stackaddr, | |
feb37183 | 401 | size_t __stacksize) __THROW __nonnull ((1)); |
76a50749 UD |
402 | #endif |
403 | ||
404 | #ifdef __USE_GNU | |
80f536db UD |
405 | /* Thread created with attribute ATTR will be limited to run only on |
406 | the processors represented in CPUSET. */ | |
407 | extern int pthread_attr_setaffinity_np (pthread_attr_t *__attr, | |
439ff07b | 408 | size_t __cpusetsize, |
a784e502 | 409 | const cpu_set_t *__cpuset) |
feb37183 | 410 | __THROW __nonnull ((1, 3)); |
80f536db UD |
411 | |
412 | /* Get bit set in CPUSET representing the processors threads created with | |
413 | ATTR can run on. */ | |
a784e502 | 414 | extern int pthread_attr_getaffinity_np (const pthread_attr_t *__attr, |
439ff07b | 415 | size_t __cpusetsize, |
feb37183 UD |
416 | cpu_set_t *__cpuset) |
417 | __THROW __nonnull ((1, 3)); | |
80f536db | 418 | |
61dd6208 SP |
419 | /* Get the default attributes used by pthread_create in this process. */ |
420 | extern int pthread_getattr_default_np (pthread_attr_t *__attr) | |
421 | __THROW __nonnull ((1)); | |
422 | ||
423 | /* Set the default attributes to be used by pthread_create in this | |
424 | process. */ | |
425 | extern int pthread_setattr_default_np (const pthread_attr_t *__attr) | |
426 | __THROW __nonnull ((1)); | |
80f536db | 427 | |
9ba96eda | 428 | /* Initialize thread attribute *ATTR with attributes corresponding to the |
e4d6e7f5 | 429 | already running thread TH. It shall be called on uninitialized ATTR |
9ba96eda | 430 | and destroyed with pthread_attr_destroy when no longer needed. */ |
feb37183 UD |
431 | extern int pthread_getattr_np (pthread_t __th, pthread_attr_t *__attr) |
432 | __THROW __nonnull ((2)); | |
76a50749 UD |
433 | #endif |
434 | ||
435 | ||
436 | /* Functions for scheduling control. */ | |
437 | ||
438 | /* Set the scheduling parameters for TARGET_THREAD according to POLICY | |
439 | and *PARAM. */ | |
440 | extern int pthread_setschedparam (pthread_t __target_thread, int __policy, | |
a784e502 | 441 | const struct sched_param *__param) |
feb37183 | 442 | __THROW __nonnull ((3)); |
76a50749 UD |
443 | |
444 | /* Return in *POLICY and *PARAM the scheduling parameters for TARGET_THREAD. */ | |
445 | extern int pthread_getschedparam (pthread_t __target_thread, | |
446 | int *__restrict __policy, | |
447 | struct sched_param *__restrict __param) | |
feb37183 | 448 | __THROW __nonnull ((2, 3)); |
76a50749 | 449 | |
f1f2cafc UD |
450 | /* Set the scheduling priority for TARGET_THREAD. */ |
451 | extern int pthread_setschedprio (pthread_t __target_thread, int __prio) | |
452 | __THROW; | |
453 | ||
76a50749 | 454 | |
86a4c67f UD |
455 | #ifdef __USE_GNU |
456 | /* Get thread name visible in the kernel and its interfaces. */ | |
457 | extern int pthread_getname_np (pthread_t __target_thread, char *__buf, | |
458 | size_t __buflen) | |
459 | __THROW __nonnull ((2)); | |
460 | ||
461 | /* Set thread name visible in the kernel and its interfaces. */ | |
a784e502 | 462 | extern int pthread_setname_np (pthread_t __target_thread, const char *__name) |
86a4c67f UD |
463 | __THROW __nonnull ((2)); |
464 | #endif | |
465 | ||
466 | ||
76a50749 UD |
467 | #ifdef __USE_UNIX98 |
468 | /* Determine level of concurrency. */ | |
469 | extern int pthread_getconcurrency (void) __THROW; | |
470 | ||
471 | /* Set new concurrency level to LEVEL. */ | |
472 | extern int pthread_setconcurrency (int __level) __THROW; | |
473 | #endif | |
474 | ||
475 | #ifdef __USE_GNU | |
476 | /* Yield the processor to another thread or process. | |
477 | This function is similar to the POSIX `sched_yield' function but | |
478 | might be differently implemented in the case of a m-on-n thread | |
479 | implementation. */ | |
480 | extern int pthread_yield (void) __THROW; | |
949ec764 UD |
481 | |
482 | ||
483 | /* Limit specified thread TH to run only on the processors represented | |
484 | in CPUSET. */ | |
439ff07b | 485 | extern int pthread_setaffinity_np (pthread_t __th, size_t __cpusetsize, |
a784e502 | 486 | const cpu_set_t *__cpuset) |
feb37183 | 487 | __THROW __nonnull ((3)); |
949ec764 UD |
488 | |
489 | /* Get bit set in CPUSET representing the processors TH can run on. */ | |
439ff07b | 490 | extern int pthread_getaffinity_np (pthread_t __th, size_t __cpusetsize, |
feb37183 UD |
491 | cpu_set_t *__cpuset) |
492 | __THROW __nonnull ((3)); | |
76a50749 UD |
493 | #endif |
494 | ||
495 | ||
496 | /* Functions for handling initialization. */ | |
497 | ||
498 | /* Guarantee that the initialization function INIT_ROUTINE will be called | |
499 | only once, even if pthread_once is executed several times with the | |
500 | same ONCE_CONTROL argument. ONCE_CONTROL must point to a static or | |
e0329987 UD |
501 | extern variable initialized to PTHREAD_ONCE_INIT. |
502 | ||
503 | The initialization functions might throw exception which is why | |
504 | this function is not marked with __THROW. */ | |
76a50749 | 505 | extern int pthread_once (pthread_once_t *__once_control, |
feb37183 | 506 | void (*__init_routine) (void)) __nonnull ((1, 2)); |
76a50749 UD |
507 | |
508 | ||
2c008571 UD |
509 | /* Functions for handling cancellation. |
510 | ||
511 | Note that these functions are explicitly not marked to not throw an | |
512 | exception in C++ code. If cancellation is implemented by unwinding | |
513 | this is necessary to have the compiler generate the unwind information. */ | |
76a50749 UD |
514 | |
515 | /* Set cancelability state of current thread to STATE, returning old | |
516 | state in *OLDSTATE if OLDSTATE is not NULL. */ | |
76a67697 | 517 | extern int pthread_setcancelstate (int __state, int *__oldstate); |
76a50749 UD |
518 | |
519 | /* Set cancellation state of current thread to TYPE, returning the old | |
520 | type in *OLDTYPE if OLDTYPE is not NULL. */ | |
76a67697 | 521 | extern int pthread_setcanceltype (int __type, int *__oldtype); |
76a50749 UD |
522 | |
523 | /* Cancel THREAD immediately or at the next possibility. */ | |
76a67697 | 524 | extern int pthread_cancel (pthread_t __th); |
76a50749 UD |
525 | |
526 | /* Test for pending cancellation for the current thread and terminate | |
527 | the thread as per pthread_exit(PTHREAD_CANCELED) if it has been | |
2c008571 | 528 | cancelled. */ |
7d74651e | 529 | extern void pthread_testcancel (void); |
76a50749 UD |
530 | |
531 | ||
09d65ff3 UD |
532 | /* Cancellation handling with integration into exception handling. */ |
533 | ||
534 | typedef struct | |
535 | { | |
09d65ff3 UD |
536 | struct |
537 | { | |
538 | __jmp_buf __cancel_jmp_buf; | |
539 | int __mask_was_saved; | |
540 | } __cancel_jmp_buf[1]; | |
68107ec0 | 541 | void *__pad[4]; |
09d65ff3 UD |
542 | } __pthread_unwind_buf_t __attribute__ ((__aligned__)); |
543 | ||
544 | /* No special attributes by default. */ | |
545 | #ifndef __cleanup_fct_attribute | |
546 | # define __cleanup_fct_attribute | |
547 | #endif | |
548 | ||
549 | ||
7726edc2 UD |
550 | /* Structure to hold the cleanup handler information. */ |
551 | struct __pthread_cleanup_frame | |
552 | { | |
553 | void (*__cancel_routine) (void *); | |
554 | void *__cancel_arg; | |
555 | int __do_it; | |
556 | int __cancel_type; | |
557 | }; | |
558 | ||
559 | #if defined __GNUC__ && defined __EXCEPTIONS | |
560 | # ifdef __cplusplus | |
561 | /* Class to handle cancellation handler invocation. */ | |
562 | class __pthread_cleanup_class | |
563 | { | |
564 | void (*__cancel_routine) (void *); | |
565 | void *__cancel_arg; | |
566 | int __do_it; | |
567 | int __cancel_type; | |
568 | ||
569 | public: | |
570 | __pthread_cleanup_class (void (*__fct) (void *), void *__arg) | |
571 | : __cancel_routine (__fct), __cancel_arg (__arg), __do_it (1) { } | |
572 | ~__pthread_cleanup_class () { if (__do_it) __cancel_routine (__cancel_arg); } | |
68b9e1ae UD |
573 | void __setdoit (int __newval) { __do_it = __newval; } |
574 | void __defer () { pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED, | |
575 | &__cancel_type); } | |
576 | void __restore () const { pthread_setcanceltype (__cancel_type, 0); } | |
7726edc2 UD |
577 | }; |
578 | ||
579 | /* Install a cleanup handler: ROUTINE will be called with arguments ARG | |
580 | when the thread is canceled or calls pthread_exit. ROUTINE will also | |
581 | be called with arguments ARG when the matching pthread_cleanup_pop | |
582 | is executed with non-zero EXECUTE argument. | |
583 | ||
584 | pthread_cleanup_push and pthread_cleanup_pop are macros and must always | |
585 | be used in matching pairs at the same nesting level of braces. */ | |
586 | # define pthread_cleanup_push(routine, arg) \ | |
587 | do { \ | |
588 | __pthread_cleanup_class __clframe (routine, arg) | |
589 | ||
590 | /* Remove a cleanup handler installed by the matching pthread_cleanup_push. | |
591 | If EXECUTE is non-zero, the handler function is called. */ | |
592 | # define pthread_cleanup_pop(execute) \ | |
593 | __clframe.__setdoit (execute); \ | |
594 | } while (0) | |
595 | ||
596 | # ifdef __USE_GNU | |
597 | /* Install a cleanup handler as pthread_cleanup_push does, but also | |
598 | saves the current cancellation type and sets it to deferred | |
599 | cancellation. */ | |
600 | # define pthread_cleanup_push_defer_np(routine, arg) \ | |
601 | do { \ | |
602 | __pthread_cleanup_class __clframe (routine, arg); \ | |
603 | __clframe.__defer () | |
604 | ||
605 | /* Remove a cleanup handler as pthread_cleanup_pop does, but also | |
606 | restores the cancellation type that was in effect when the matching | |
607 | pthread_cleanup_push_defer was called. */ | |
608 | # define pthread_cleanup_pop_restore_np(execute) \ | |
609 | __clframe.__restore (); \ | |
610 | __clframe.__setdoit (execute); \ | |
611 | } while (0) | |
612 | # endif | |
613 | # else | |
614 | /* Function called to call the cleanup handler. As an extern inline | |
615 | function the compiler is free to decide inlining the change when | |
616 | needed or fall back on the copy which must exist somewhere | |
617 | else. */ | |
b037a293 | 618 | __extern_inline void |
7726edc2 UD |
619 | __pthread_cleanup_routine (struct __pthread_cleanup_frame *__frame) |
620 | { | |
621 | if (__frame->__do_it) | |
622 | __frame->__cancel_routine (__frame->__cancel_arg); | |
623 | } | |
624 | ||
76a50749 | 625 | /* Install a cleanup handler: ROUTINE will be called with arguments ARG |
7726edc2 | 626 | when the thread is canceled or calls pthread_exit. ROUTINE will also |
76a50749 UD |
627 | be called with arguments ARG when the matching pthread_cleanup_pop |
628 | is executed with non-zero EXECUTE argument. | |
629 | ||
630 | pthread_cleanup_push and pthread_cleanup_pop are macros and must always | |
631 | be used in matching pairs at the same nesting level of braces. */ | |
7726edc2 UD |
632 | # define pthread_cleanup_push(routine, arg) \ |
633 | do { \ | |
634 | struct __pthread_cleanup_frame __clframe \ | |
635 | __attribute__ ((__cleanup__ (__pthread_cleanup_routine))) \ | |
636 | = { .__cancel_routine = (routine), .__cancel_arg = (arg), \ | |
637 | .__do_it = 1 }; | |
638 | ||
639 | /* Remove a cleanup handler installed by the matching pthread_cleanup_push. | |
640 | If EXECUTE is non-zero, the handler function is called. */ | |
641 | # define pthread_cleanup_pop(execute) \ | |
642 | __clframe.__do_it = (execute); \ | |
643 | } while (0) | |
644 | ||
645 | # ifdef __USE_GNU | |
646 | /* Install a cleanup handler as pthread_cleanup_push does, but also | |
647 | saves the current cancellation type and sets it to deferred | |
648 | cancellation. */ | |
649 | # define pthread_cleanup_push_defer_np(routine, arg) \ | |
650 | do { \ | |
651 | struct __pthread_cleanup_frame __clframe \ | |
652 | __attribute__ ((__cleanup__ (__pthread_cleanup_routine))) \ | |
653 | = { .__cancel_routine = (routine), .__cancel_arg = (arg), \ | |
654 | .__do_it = 1 }; \ | |
655 | (void) pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED, \ | |
656 | &__clframe.__cancel_type) | |
657 | ||
658 | /* Remove a cleanup handler as pthread_cleanup_pop does, but also | |
659 | restores the cancellation type that was in effect when the matching | |
660 | pthread_cleanup_push_defer was called. */ | |
661 | # define pthread_cleanup_pop_restore_np(execute) \ | |
662 | (void) pthread_setcanceltype (__clframe.__cancel_type, NULL); \ | |
663 | __clframe.__do_it = (execute); \ | |
664 | } while (0) | |
665 | # endif | |
666 | # endif | |
667 | #else | |
668 | /* Install a cleanup handler: ROUTINE will be called with arguments ARG | |
669 | when the thread is canceled or calls pthread_exit. ROUTINE will also | |
670 | be called with arguments ARG when the matching pthread_cleanup_pop | |
671 | is executed with non-zero EXECUTE argument. | |
672 | ||
673 | pthread_cleanup_push and pthread_cleanup_pop are macros and must always | |
674 | be used in matching pairs at the same nesting level of braces. */ | |
675 | # define pthread_cleanup_push(routine, arg) \ | |
09d65ff3 UD |
676 | do { \ |
677 | __pthread_unwind_buf_t __cancel_buf; \ | |
678 | void (*__cancel_routine) (void *) = (routine); \ | |
679 | void *__cancel_arg = (arg); \ | |
c3758fee AS |
680 | int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) \ |
681 | __cancel_buf.__cancel_jmp_buf, 0); \ | |
4af3879c | 682 | if (__glibc_unlikely (__not_first_call)) \ |
09d65ff3 UD |
683 | { \ |
684 | __cancel_routine (__cancel_arg); \ | |
685 | __pthread_unwind_next (&__cancel_buf); \ | |
686 | /* NOTREACHED */ \ | |
687 | } \ | |
688 | \ | |
689 | __pthread_register_cancel (&__cancel_buf); \ | |
690 | do { | |
691 | extern void __pthread_register_cancel (__pthread_unwind_buf_t *__buf) | |
692 | __cleanup_fct_attribute; | |
76a50749 UD |
693 | |
694 | /* Remove a cleanup handler installed by the matching pthread_cleanup_push. | |
695 | If EXECUTE is non-zero, the handler function is called. */ | |
7726edc2 | 696 | # define pthread_cleanup_pop(execute) \ |
135460f4 | 697 | do { } while (0);/* Empty to allow label before pthread_cleanup_pop. */\ |
09d65ff3 UD |
698 | } while (0); \ |
699 | __pthread_unregister_cancel (&__cancel_buf); \ | |
700 | if (execute) \ | |
701 | __cancel_routine (__cancel_arg); \ | |
702 | } while (0) | |
703 | extern void __pthread_unregister_cancel (__pthread_unwind_buf_t *__buf) | |
704 | __cleanup_fct_attribute; | |
76a50749 | 705 | |
7726edc2 | 706 | # ifdef __USE_GNU |
76a50749 UD |
707 | /* Install a cleanup handler as pthread_cleanup_push does, but also |
708 | saves the current cancellation type and sets it to deferred | |
709 | cancellation. */ | |
7726edc2 | 710 | # define pthread_cleanup_push_defer_np(routine, arg) \ |
09d65ff3 UD |
711 | do { \ |
712 | __pthread_unwind_buf_t __cancel_buf; \ | |
713 | void (*__cancel_routine) (void *) = (routine); \ | |
714 | void *__cancel_arg = (arg); \ | |
c3758fee AS |
715 | int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) \ |
716 | __cancel_buf.__cancel_jmp_buf, 0); \ | |
0d522f64 | 717 | if (__glibc_unlikely (__not_first_call)) \ |
09d65ff3 UD |
718 | { \ |
719 | __cancel_routine (__cancel_arg); \ | |
720 | __pthread_unwind_next (&__cancel_buf); \ | |
721 | /* NOTREACHED */ \ | |
722 | } \ | |
723 | \ | |
724 | __pthread_register_cancel_defer (&__cancel_buf); \ | |
725 | do { | |
726 | extern void __pthread_register_cancel_defer (__pthread_unwind_buf_t *__buf) | |
727 | __cleanup_fct_attribute; | |
76a50749 UD |
728 | |
729 | /* Remove a cleanup handler as pthread_cleanup_pop does, but also | |
730 | restores the cancellation type that was in effect when the matching | |
731 | pthread_cleanup_push_defer was called. */ | |
7726edc2 | 732 | # define pthread_cleanup_pop_restore_np(execute) \ |
135460f4 | 733 | do { } while (0);/* Empty to allow label before pthread_cleanup_pop. */\ |
09d65ff3 UD |
734 | } while (0); \ |
735 | __pthread_unregister_cancel_restore (&__cancel_buf); \ | |
736 | if (execute) \ | |
737 | __cancel_routine (__cancel_arg); \ | |
738 | } while (0) | |
739 | extern void __pthread_unregister_cancel_restore (__pthread_unwind_buf_t *__buf) | |
740 | __cleanup_fct_attribute; | |
7726edc2 | 741 | # endif |
76a50749 | 742 | |
09d65ff3 UD |
743 | /* Internal interface to initiate cleanup. */ |
744 | extern void __pthread_unwind_next (__pthread_unwind_buf_t *__buf) | |
16feadf2 | 745 | __cleanup_fct_attribute __attribute__ ((__noreturn__)) |
7726edc2 | 746 | # ifndef SHARED |
16feadf2 | 747 | __attribute__ ((__weak__)) |
7726edc2 | 748 | # endif |
09d65ff3 | 749 | ; |
7726edc2 | 750 | #endif |
09d65ff3 UD |
751 | |
752 | /* Function used in the macros. */ | |
753 | struct __jmp_buf_tag; | |
97bc38d7 | 754 | extern int __sigsetjmp (struct __jmp_buf_tag *__env, int __savemask) __THROWNL; |
76a50749 UD |
755 | |
756 | ||
757 | /* Mutex handling. */ | |
758 | ||
759 | /* Initialize a mutex. */ | |
760 | extern int pthread_mutex_init (pthread_mutex_t *__mutex, | |
a784e502 | 761 | const pthread_mutexattr_t *__mutexattr) |
feb37183 | 762 | __THROW __nonnull ((1)); |
76a50749 UD |
763 | |
764 | /* Destroy a mutex. */ | |
feb37183 UD |
765 | extern int pthread_mutex_destroy (pthread_mutex_t *__mutex) |
766 | __THROW __nonnull ((1)); | |
76a50749 UD |
767 | |
768 | /* Try locking a mutex. */ | |
feb37183 | 769 | extern int pthread_mutex_trylock (pthread_mutex_t *__mutex) |
3871f58f | 770 | __THROWNL __nonnull ((1)); |
76a50749 UD |
771 | |
772 | /* Lock a mutex. */ | |
feb37183 | 773 | extern int pthread_mutex_lock (pthread_mutex_t *__mutex) |
3871f58f | 774 | __THROWNL __nonnull ((1)); |
76a50749 UD |
775 | |
776 | #ifdef __USE_XOPEN2K | |
777 | /* Wait until lock becomes available, or specified time passes. */ | |
778 | extern int pthread_mutex_timedlock (pthread_mutex_t *__restrict __mutex, | |
a784e502 | 779 | const struct timespec *__restrict |
3871f58f | 780 | __abstime) __THROWNL __nonnull ((1, 2)); |
76a50749 UD |
781 | #endif |
782 | ||
783 | /* Unlock a mutex. */ | |
feb37183 | 784 | extern int pthread_mutex_unlock (pthread_mutex_t *__mutex) |
3871f58f | 785 | __THROWNL __nonnull ((1)); |
76a50749 UD |
786 | |
787 | ||
a5f2bd86 | 788 | /* Get the priority ceiling of MUTEX. */ |
a784e502 | 789 | extern int pthread_mutex_getprioceiling (const pthread_mutex_t * |
a5f2bd86 RM |
790 | __restrict __mutex, |
791 | int *__restrict __prioceiling) | |
feb37183 | 792 | __THROW __nonnull ((1, 2)); |
a5f2bd86 RM |
793 | |
794 | /* Set the priority ceiling of MUTEX to PRIOCEILING, return old | |
795 | priority ceiling value in *OLD_CEILING. */ | |
796 | extern int pthread_mutex_setprioceiling (pthread_mutex_t *__restrict __mutex, | |
797 | int __prioceiling, | |
798 | int *__restrict __old_ceiling) | |
feb37183 | 799 | __THROW __nonnull ((1, 3)); |
a5f2bd86 RM |
800 | |
801 | ||
77db439e | 802 | #ifdef __USE_XOPEN2K8 |
1bcfb5a5 | 803 | /* Declare the state protected by MUTEX as consistent. */ |
f095bb72 | 804 | extern int pthread_mutex_consistent (pthread_mutex_t *__mutex) |
feb37183 | 805 | __THROW __nonnull ((1)); |
77db439e UD |
806 | # ifdef __USE_GNU |
807 | extern int pthread_mutex_consistent_np (pthread_mutex_t *__mutex) | |
808 | __THROW __nonnull ((1)); | |
809 | # endif | |
1bcfb5a5 UD |
810 | #endif |
811 | ||
812 | ||
76a50749 UD |
813 | /* Functions for handling mutex attributes. */ |
814 | ||
815 | /* Initialize mutex attribute object ATTR with default attributes | |
816 | (kind is PTHREAD_MUTEX_TIMED_NP). */ | |
feb37183 UD |
817 | extern int pthread_mutexattr_init (pthread_mutexattr_t *__attr) |
818 | __THROW __nonnull ((1)); | |
76a50749 UD |
819 | |
820 | /* Destroy mutex attribute object ATTR. */ | |
feb37183 UD |
821 | extern int pthread_mutexattr_destroy (pthread_mutexattr_t *__attr) |
822 | __THROW __nonnull ((1)); | |
76a50749 UD |
823 | |
824 | /* Get the process-shared flag of the mutex attribute ATTR. */ | |
a784e502 | 825 | extern int pthread_mutexattr_getpshared (const pthread_mutexattr_t * |
76a50749 | 826 | __restrict __attr, |
feb37183 UD |
827 | int *__restrict __pshared) |
828 | __THROW __nonnull ((1, 2)); | |
76a50749 UD |
829 | |
830 | /* Set the process-shared flag of the mutex attribute ATTR. */ | |
831 | extern int pthread_mutexattr_setpshared (pthread_mutexattr_t *__attr, | |
feb37183 UD |
832 | int __pshared) |
833 | __THROW __nonnull ((1)); | |
76a50749 | 834 | |
d3c7e686 | 835 | #if defined __USE_UNIX98 || defined __USE_XOPEN2K8 |
76a50749 | 836 | /* Return in *KIND the mutex kind attribute in *ATTR. */ |
a784e502 | 837 | extern int pthread_mutexattr_gettype (const pthread_mutexattr_t *__restrict |
feb37183 UD |
838 | __attr, int *__restrict __kind) |
839 | __THROW __nonnull ((1, 2)); | |
76a50749 UD |
840 | |
841 | /* Set the mutex kind attribute in *ATTR to KIND (either PTHREAD_MUTEX_NORMAL, | |
842 | PTHREAD_MUTEX_RECURSIVE, PTHREAD_MUTEX_ERRORCHECK, or | |
843 | PTHREAD_MUTEX_DEFAULT). */ | |
844 | extern int pthread_mutexattr_settype (pthread_mutexattr_t *__attr, int __kind) | |
feb37183 | 845 | __THROW __nonnull ((1)); |
d3c7e686 | 846 | #endif |
a5f2bd86 RM |
847 | |
848 | /* Return in *PROTOCOL the mutex protocol attribute in *ATTR. */ | |
a784e502 | 849 | extern int pthread_mutexattr_getprotocol (const pthread_mutexattr_t * |
a5f2bd86 | 850 | __restrict __attr, |
feb37183 UD |
851 | int *__restrict __protocol) |
852 | __THROW __nonnull ((1, 2)); | |
a5f2bd86 RM |
853 | |
854 | /* Set the mutex protocol attribute in *ATTR to PROTOCOL (either | |
855 | PTHREAD_PRIO_NONE, PTHREAD_PRIO_INHERIT, or PTHREAD_PRIO_PROTECT). */ | |
856 | extern int pthread_mutexattr_setprotocol (pthread_mutexattr_t *__attr, | |
feb37183 UD |
857 | int __protocol) |
858 | __THROW __nonnull ((1)); | |
a5f2bd86 RM |
859 | |
860 | /* Return in *PRIOCEILING the mutex prioceiling attribute in *ATTR. */ | |
a784e502 | 861 | extern int pthread_mutexattr_getprioceiling (const pthread_mutexattr_t * |
a5f2bd86 RM |
862 | __restrict __attr, |
863 | int *__restrict __prioceiling) | |
feb37183 | 864 | __THROW __nonnull ((1, 2)); |
a5f2bd86 RM |
865 | |
866 | /* Set the mutex prioceiling attribute in *ATTR to PRIOCEILING. */ | |
867 | extern int pthread_mutexattr_setprioceiling (pthread_mutexattr_t *__attr, | |
feb37183 UD |
868 | int __prioceiling) |
869 | __THROW __nonnull ((1)); | |
76a50749 | 870 | |
77db439e | 871 | #ifdef __USE_XOPEN2K |
1bcfb5a5 | 872 | /* Get the robustness flag of the mutex attribute ATTR. */ |
a784e502 | 873 | extern int pthread_mutexattr_getrobust (const pthread_mutexattr_t *__attr, |
77db439e UD |
874 | int *__robustness) |
875 | __THROW __nonnull ((1, 2)); | |
876 | # ifdef __USE_GNU | |
a784e502 | 877 | extern int pthread_mutexattr_getrobust_np (const pthread_mutexattr_t *__attr, |
feb37183 UD |
878 | int *__robustness) |
879 | __THROW __nonnull ((1, 2)); | |
77db439e | 880 | # endif |
1bcfb5a5 UD |
881 | |
882 | /* Set the robustness flag of the mutex attribute ATTR. */ | |
77db439e UD |
883 | extern int pthread_mutexattr_setrobust (pthread_mutexattr_t *__attr, |
884 | int __robustness) | |
885 | __THROW __nonnull ((1)); | |
886 | # ifdef __USE_GNU | |
1bcfb5a5 | 887 | extern int pthread_mutexattr_setrobust_np (pthread_mutexattr_t *__attr, |
feb37183 UD |
888 | int __robustness) |
889 | __THROW __nonnull ((1)); | |
77db439e | 890 | # endif |
1bcfb5a5 UD |
891 | #endif |
892 | ||
76a50749 | 893 | |
ccc63b07 | 894 | #if defined __USE_UNIX98 || defined __USE_XOPEN2K |
76a50749 UD |
895 | /* Functions for handling read-write locks. */ |
896 | ||
897 | /* Initialize read-write lock RWLOCK using attributes ATTR, or use | |
898 | the default values if later is NULL. */ | |
899 | extern int pthread_rwlock_init (pthread_rwlock_t *__restrict __rwlock, | |
a784e502 | 900 | const pthread_rwlockattr_t *__restrict |
feb37183 | 901 | __attr) __THROW __nonnull ((1)); |
76a50749 UD |
902 | |
903 | /* Destroy read-write lock RWLOCK. */ | |
feb37183 UD |
904 | extern int pthread_rwlock_destroy (pthread_rwlock_t *__rwlock) |
905 | __THROW __nonnull ((1)); | |
76a50749 UD |
906 | |
907 | /* Acquire read lock for RWLOCK. */ | |
feb37183 | 908 | extern int pthread_rwlock_rdlock (pthread_rwlock_t *__rwlock) |
3871f58f | 909 | __THROWNL __nonnull ((1)); |
76a50749 UD |
910 | |
911 | /* Try to acquire read lock for RWLOCK. */ | |
feb37183 | 912 | extern int pthread_rwlock_tryrdlock (pthread_rwlock_t *__rwlock) |
3871f58f | 913 | __THROWNL __nonnull ((1)); |
76a50749 UD |
914 | |
915 | # ifdef __USE_XOPEN2K | |
916 | /* Try to acquire read lock for RWLOCK or return after specfied time. */ | |
917 | extern int pthread_rwlock_timedrdlock (pthread_rwlock_t *__restrict __rwlock, | |
a784e502 | 918 | const struct timespec *__restrict |
3871f58f | 919 | __abstime) __THROWNL __nonnull ((1, 2)); |
76a50749 UD |
920 | # endif |
921 | ||
922 | /* Acquire write lock for RWLOCK. */ | |
feb37183 | 923 | extern int pthread_rwlock_wrlock (pthread_rwlock_t *__rwlock) |
3871f58f | 924 | __THROWNL __nonnull ((1)); |
76a50749 UD |
925 | |
926 | /* Try to acquire write lock for RWLOCK. */ | |
feb37183 | 927 | extern int pthread_rwlock_trywrlock (pthread_rwlock_t *__rwlock) |
3871f58f | 928 | __THROWNL __nonnull ((1)); |
76a50749 UD |
929 | |
930 | # ifdef __USE_XOPEN2K | |
931 | /* Try to acquire write lock for RWLOCK or return after specfied time. */ | |
932 | extern int pthread_rwlock_timedwrlock (pthread_rwlock_t *__restrict __rwlock, | |
a784e502 | 933 | const struct timespec *__restrict |
3871f58f | 934 | __abstime) __THROWNL __nonnull ((1, 2)); |
76a50749 UD |
935 | # endif |
936 | ||
937 | /* Unlock RWLOCK. */ | |
feb37183 | 938 | extern int pthread_rwlock_unlock (pthread_rwlock_t *__rwlock) |
3871f58f | 939 | __THROWNL __nonnull ((1)); |
76a50749 UD |
940 | |
941 | ||
942 | /* Functions for handling read-write lock attributes. */ | |
943 | ||
944 | /* Initialize attribute object ATTR with default values. */ | |
feb37183 UD |
945 | extern int pthread_rwlockattr_init (pthread_rwlockattr_t *__attr) |
946 | __THROW __nonnull ((1)); | |
76a50749 UD |
947 | |
948 | /* Destroy attribute object ATTR. */ | |
feb37183 UD |
949 | extern int pthread_rwlockattr_destroy (pthread_rwlockattr_t *__attr) |
950 | __THROW __nonnull ((1)); | |
76a50749 UD |
951 | |
952 | /* Return current setting of process-shared attribute of ATTR in PSHARED. */ | |
a784e502 | 953 | extern int pthread_rwlockattr_getpshared (const pthread_rwlockattr_t * |
76a50749 | 954 | __restrict __attr, |
feb37183 UD |
955 | int *__restrict __pshared) |
956 | __THROW __nonnull ((1, 2)); | |
76a50749 UD |
957 | |
958 | /* Set process-shared attribute of ATTR to PSHARED. */ | |
959 | extern int pthread_rwlockattr_setpshared (pthread_rwlockattr_t *__attr, | |
feb37183 UD |
960 | int __pshared) |
961 | __THROW __nonnull ((1)); | |
76a50749 UD |
962 | |
963 | /* Return current setting of reader/writer preference. */ | |
a784e502 | 964 | extern int pthread_rwlockattr_getkind_np (const pthread_rwlockattr_t * |
76a50749 | 965 | __restrict __attr, |
feb37183 UD |
966 | int *__restrict __pref) |
967 | __THROW __nonnull ((1, 2)); | |
76a50749 UD |
968 | |
969 | /* Set reader/write preference. */ | |
970 | extern int pthread_rwlockattr_setkind_np (pthread_rwlockattr_t *__attr, | |
feb37183 | 971 | int __pref) __THROW __nonnull ((1)); |
76a50749 UD |
972 | #endif |
973 | ||
974 | ||
975 | /* Functions for handling conditional variables. */ | |
976 | ||
977 | /* Initialize condition variable COND using attributes ATTR, or use | |
978 | the default values if later is NULL. */ | |
979 | extern int pthread_cond_init (pthread_cond_t *__restrict __cond, | |
a784e502 UD |
980 | const pthread_condattr_t *__restrict __cond_attr) |
981 | __THROW __nonnull ((1)); | |
76a50749 UD |
982 | |
983 | /* Destroy condition variable COND. */ | |
feb37183 UD |
984 | extern int pthread_cond_destroy (pthread_cond_t *__cond) |
985 | __THROW __nonnull ((1)); | |
76a50749 UD |
986 | |
987 | /* Wake up one thread waiting for condition variable COND. */ | |
feb37183 | 988 | extern int pthread_cond_signal (pthread_cond_t *__cond) |
3871f58f | 989 | __THROWNL __nonnull ((1)); |
76a50749 UD |
990 | |
991 | /* Wake up all threads waiting for condition variables COND. */ | |
feb37183 | 992 | extern int pthread_cond_broadcast (pthread_cond_t *__cond) |
3871f58f | 993 | __THROWNL __nonnull ((1)); |
76a50749 UD |
994 | |
995 | /* Wait for condition variable COND to be signaled or broadcast. | |
4e648ea3 UD |
996 | MUTEX is assumed to be locked before. |
997 | ||
998 | This function is a cancellation point and therefore not marked with | |
999 | __THROW. */ | |
76a50749 | 1000 | extern int pthread_cond_wait (pthread_cond_t *__restrict __cond, |
feb37183 UD |
1001 | pthread_mutex_t *__restrict __mutex) |
1002 | __nonnull ((1, 2)); | |
76a50749 UD |
1003 | |
1004 | /* Wait for condition variable COND to be signaled or broadcast until | |
1005 | ABSTIME. MUTEX is assumed to be locked before. ABSTIME is an | |
1006 | absolute time specification; zero is the beginning of the epoch | |
4e648ea3 UD |
1007 | (00:00:00 GMT, January 1, 1970). |
1008 | ||
1009 | This function is a cancellation point and therefore not marked with | |
1010 | __THROW. */ | |
76a50749 UD |
1011 | extern int pthread_cond_timedwait (pthread_cond_t *__restrict __cond, |
1012 | pthread_mutex_t *__restrict __mutex, | |
a784e502 UD |
1013 | const struct timespec *__restrict __abstime) |
1014 | __nonnull ((1, 2, 3)); | |
76a50749 UD |
1015 | |
1016 | /* Functions for handling condition variable attributes. */ | |
1017 | ||
1018 | /* Initialize condition variable attribute ATTR. */ | |
feb37183 UD |
1019 | extern int pthread_condattr_init (pthread_condattr_t *__attr) |
1020 | __THROW __nonnull ((1)); | |
76a50749 UD |
1021 | |
1022 | /* Destroy condition variable attribute ATTR. */ | |
feb37183 UD |
1023 | extern int pthread_condattr_destroy (pthread_condattr_t *__attr) |
1024 | __THROW __nonnull ((1)); | |
76a50749 UD |
1025 | |
1026 | /* Get the process-shared flag of the condition variable attribute ATTR. */ | |
a784e502 | 1027 | extern int pthread_condattr_getpshared (const pthread_condattr_t * |
f095bb72 UD |
1028 | __restrict __attr, |
1029 | int *__restrict __pshared) | |
feb37183 | 1030 | __THROW __nonnull ((1, 2)); |
76a50749 UD |
1031 | |
1032 | /* Set the process-shared flag of the condition variable attribute ATTR. */ | |
1033 | extern int pthread_condattr_setpshared (pthread_condattr_t *__attr, | |
f095bb72 | 1034 | int __pshared) __THROW __nonnull ((1)); |
76a50749 | 1035 | |
86a9ee5e | 1036 | #ifdef __USE_XOPEN2K |
382466e0 | 1037 | /* Get the clock selected for the condition variable attribute ATTR. */ |
a784e502 | 1038 | extern int pthread_condattr_getclock (const pthread_condattr_t * |
86a9ee5e UD |
1039 | __restrict __attr, |
1040 | __clockid_t *__restrict __clock_id) | |
feb37183 | 1041 | __THROW __nonnull ((1, 2)); |
86a9ee5e | 1042 | |
382466e0 | 1043 | /* Set the clock selected for the condition variable attribute ATTR. */ |
86a9ee5e | 1044 | extern int pthread_condattr_setclock (pthread_condattr_t *__attr, |
feb37183 UD |
1045 | __clockid_t __clock_id) |
1046 | __THROW __nonnull ((1)); | |
86a9ee5e | 1047 | #endif |
76a50749 UD |
1048 | |
1049 | ||
1050 | #ifdef __USE_XOPEN2K | |
1051 | /* Functions to handle spinlocks. */ | |
1052 | ||
1053 | /* Initialize the spinlock LOCK. If PSHARED is nonzero the spinlock can | |
1054 | be shared between different processes. */ | |
1055 | extern int pthread_spin_init (pthread_spinlock_t *__lock, int __pshared) | |
feb37183 | 1056 | __THROW __nonnull ((1)); |
76a50749 UD |
1057 | |
1058 | /* Destroy the spinlock LOCK. */ | |
feb37183 UD |
1059 | extern int pthread_spin_destroy (pthread_spinlock_t *__lock) |
1060 | __THROW __nonnull ((1)); | |
76a50749 UD |
1061 | |
1062 | /* Wait until spinlock LOCK is retrieved. */ | |
feb37183 | 1063 | extern int pthread_spin_lock (pthread_spinlock_t *__lock) |
3871f58f | 1064 | __THROWNL __nonnull ((1)); |
76a50749 UD |
1065 | |
1066 | /* Try to lock spinlock LOCK. */ | |
feb37183 | 1067 | extern int pthread_spin_trylock (pthread_spinlock_t *__lock) |
3871f58f | 1068 | __THROWNL __nonnull ((1)); |
76a50749 UD |
1069 | |
1070 | /* Release spinlock LOCK. */ | |
feb37183 | 1071 | extern int pthread_spin_unlock (pthread_spinlock_t *__lock) |
3871f58f | 1072 | __THROWNL __nonnull ((1)); |
76a50749 UD |
1073 | |
1074 | ||
1075 | /* Functions to handle barriers. */ | |
1076 | ||
1077 | /* Initialize BARRIER with the attributes in ATTR. The barrier is | |
1078 | opened when COUNT waiters arrived. */ | |
1079 | extern int pthread_barrier_init (pthread_barrier_t *__restrict __barrier, | |
a784e502 | 1080 | const pthread_barrierattr_t *__restrict |
feb37183 UD |
1081 | __attr, unsigned int __count) |
1082 | __THROW __nonnull ((1)); | |
76a50749 UD |
1083 | |
1084 | /* Destroy a previously dynamically initialized barrier BARRIER. */ | |
feb37183 UD |
1085 | extern int pthread_barrier_destroy (pthread_barrier_t *__barrier) |
1086 | __THROW __nonnull ((1)); | |
76a50749 UD |
1087 | |
1088 | /* Wait on barrier BARRIER. */ | |
feb37183 | 1089 | extern int pthread_barrier_wait (pthread_barrier_t *__barrier) |
3871f58f | 1090 | __THROWNL __nonnull ((1)); |
76a50749 UD |
1091 | |
1092 | ||
1093 | /* Initialize barrier attribute ATTR. */ | |
feb37183 UD |
1094 | extern int pthread_barrierattr_init (pthread_barrierattr_t *__attr) |
1095 | __THROW __nonnull ((1)); | |
76a50749 UD |
1096 | |
1097 | /* Destroy previously dynamically initialized barrier attribute ATTR. */ | |
feb37183 UD |
1098 | extern int pthread_barrierattr_destroy (pthread_barrierattr_t *__attr) |
1099 | __THROW __nonnull ((1)); | |
76a50749 UD |
1100 | |
1101 | /* Get the process-shared flag of the barrier attribute ATTR. */ | |
a784e502 | 1102 | extern int pthread_barrierattr_getpshared (const pthread_barrierattr_t * |
76a50749 | 1103 | __restrict __attr, |
feb37183 UD |
1104 | int *__restrict __pshared) |
1105 | __THROW __nonnull ((1, 2)); | |
76a50749 UD |
1106 | |
1107 | /* Set the process-shared flag of the barrier attribute ATTR. */ | |
1108 | extern int pthread_barrierattr_setpshared (pthread_barrierattr_t *__attr, | |
f095bb72 | 1109 | int __pshared) |
feb37183 | 1110 | __THROW __nonnull ((1)); |
76a50749 UD |
1111 | #endif |
1112 | ||
1113 | ||
1114 | /* Functions for handling thread-specific data. */ | |
1115 | ||
1116 | /* Create a key value identifying a location in the thread-specific | |
1117 | data area. Each thread maintains a distinct thread-specific data | |
1118 | area. DESTR_FUNCTION, if non-NULL, is called with the value | |
1119 | associated to that key when the key is destroyed. | |
1120 | DESTR_FUNCTION is not called if the value associated is NULL when | |
1121 | the key is destroyed. */ | |
1122 | extern int pthread_key_create (pthread_key_t *__key, | |
feb37183 UD |
1123 | void (*__destr_function) (void *)) |
1124 | __THROW __nonnull ((1)); | |
76a50749 UD |
1125 | |
1126 | /* Destroy KEY. */ | |
1127 | extern int pthread_key_delete (pthread_key_t __key) __THROW; | |
1128 | ||
1129 | /* Return current value of the thread-specific data slot identified by KEY. */ | |
1130 | extern void *pthread_getspecific (pthread_key_t __key) __THROW; | |
1131 | ||
1132 | /* Store POINTER in the thread-specific data slot identified by KEY. */ | |
1133 | extern int pthread_setspecific (pthread_key_t __key, | |
a784e502 | 1134 | const void *__pointer) __THROW ; |
76a50749 UD |
1135 | |
1136 | ||
76a50749 UD |
1137 | #ifdef __USE_XOPEN2K |
1138 | /* Get ID of CPU-time clock for thread THREAD_ID. */ | |
1139 | extern int pthread_getcpuclockid (pthread_t __thread_id, | |
feb37183 UD |
1140 | __clockid_t *__clock_id) |
1141 | __THROW __nonnull ((2)); | |
76a50749 UD |
1142 | #endif |
1143 | ||
1144 | ||
1145 | /* Install handlers to be called when a new process is created with FORK. | |
1146 | The PREPARE handler is called in the parent process just before performing | |
1147 | FORK. The PARENT handler is called in the parent process just after FORK. | |
1148 | The CHILD handler is called in the child process. Each of the three | |
1149 | handlers can be NULL, meaning that no handler needs to be called at that | |
1150 | point. | |
1151 | PTHREAD_ATFORK can be called several times, in which case the PREPARE | |
1152 | handlers are called in LIFO order (last added with PTHREAD_ATFORK, | |
1153 | first called before FORK), and the PARENT and CHILD handlers are called | |
1154 | in FIFO (first added, first called). */ | |
1155 | ||
1156 | extern int pthread_atfork (void (*__prepare) (void), | |
1157 | void (*__parent) (void), | |
1158 | void (*__child) (void)) __THROW; | |
1159 | ||
c26ca5e1 UD |
1160 | |
1161 | #ifdef __USE_EXTERN_INLINES | |
1162 | /* Optimizations. */ | |
b037a293 | 1163 | __extern_inline int |
c26ca5e1 UD |
1164 | __NTH (pthread_equal (pthread_t __thread1, pthread_t __thread2)) |
1165 | { | |
1166 | return __thread1 == __thread2; | |
1167 | } | |
1168 | #endif | |
1169 | ||
76a50749 UD |
1170 | __END_DECLS |
1171 | ||
1172 | #endif /* pthread.h */ |