blob: 38d566731c098abb28d3eb851ff65f6e2cb9be32 [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001/* Linuxthreads - a simple clone()-based implementation of Posix */
2/* threads for Linux. */
3/* Copyright (C) 1996 Xavier Leroy (Xavier.Leroy@inria.fr) */
4/* */
5/* This program is free software; you can redistribute it and/or */
6/* modify it under the terms of the GNU Library General Public License */
7/* as published by the Free Software Foundation; either version 2 */
8/* of the License, or (at your option) any later version. */
9/* */
10/* This program is distributed in the hope that it will be useful, */
11/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
12/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
13/* GNU Library General Public License for more details. */
14
15#ifndef _PTHREAD_H
16#define _PTHREAD_H 1
17
18#include <features.h>
19
20#include <sched.h>
21#include <time.h>
22
23#define __need_sigset_t
24#include <signal.h>
25#include <bits/pthreadtypes.h>
26#include <bits/initspin.h>
27
28
29__BEGIN_DECLS
30
31/* Initializers. */
32
33#define PTHREAD_MUTEX_INITIALIZER \
34 {0, 0, 0, PTHREAD_MUTEX_ADAPTIVE_NP, __LOCK_INITIALIZER}
35#ifdef __USE_GNU
36# define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \
37 {0, 0, 0, PTHREAD_MUTEX_RECURSIVE_NP, __LOCK_INITIALIZER}
38# define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \
39 {0, 0, 0, PTHREAD_MUTEX_ERRORCHECK_NP, __LOCK_INITIALIZER}
40# define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP \
41 {0, 0, 0, PTHREAD_MUTEX_ADAPTIVE_NP, __LOCK_INITIALIZER}
42#endif
43
44#define PTHREAD_COND_INITIALIZER {__LOCK_INITIALIZER, 0}
45
46#if defined __USE_UNIX98 || defined __USE_XOPEN2K
47# define PTHREAD_RWLOCK_INITIALIZER \
48 { __LOCK_INITIALIZER, 0, NULL, NULL, NULL, \
49 PTHREAD_RWLOCK_DEFAULT_NP, PTHREAD_PROCESS_PRIVATE }
50#endif
51#ifdef __USE_GNU
52# define PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP \
53 { __LOCK_INITIALIZER, 0, NULL, NULL, NULL, \
54 PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP, PTHREAD_PROCESS_PRIVATE }
55#endif
56
57/* Values for attributes. */
58
59enum
60{
61 PTHREAD_CREATE_JOINABLE,
62#define PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_JOINABLE
63 PTHREAD_CREATE_DETACHED
64#define PTHREAD_CREATE_DETACHED PTHREAD_CREATE_DETACHED
65};
66
67enum
68{
69 PTHREAD_INHERIT_SCHED,
70#define PTHREAD_INHERIT_SCHED PTHREAD_INHERIT_SCHED
71 PTHREAD_EXPLICIT_SCHED
72#define PTHREAD_EXPLICIT_SCHED PTHREAD_EXPLICIT_SCHED
73};
74
75enum
76{
77 PTHREAD_SCOPE_SYSTEM,
78#define PTHREAD_SCOPE_SYSTEM PTHREAD_SCOPE_SYSTEM
79 PTHREAD_SCOPE_PROCESS
80#define PTHREAD_SCOPE_PROCESS PTHREAD_SCOPE_PROCESS
81};
82
83enum
84{
85 PTHREAD_MUTEX_ADAPTIVE_NP,
86 PTHREAD_MUTEX_RECURSIVE_NP,
87 PTHREAD_MUTEX_ERRORCHECK_NP,
88 PTHREAD_MUTEX_TIMED_NP
89#ifdef __USE_UNIX98
90 ,
91 PTHREAD_MUTEX_NORMAL = PTHREAD_MUTEX_ADAPTIVE_NP,
92 PTHREAD_MUTEX_RECURSIVE = PTHREAD_MUTEX_RECURSIVE_NP,
93 PTHREAD_MUTEX_ERRORCHECK = PTHREAD_MUTEX_ERRORCHECK_NP,
94 PTHREAD_MUTEX_DEFAULT = PTHREAD_MUTEX_NORMAL
95#endif
96#ifdef __USE_GNU
97 /* For compatibility. */
98 , PTHREAD_MUTEX_FAST_NP = PTHREAD_MUTEX_ADAPTIVE_NP
99#endif
100};
101
102enum
103{
104 PTHREAD_PROCESS_PRIVATE,
105#define PTHREAD_PROCESS_PRIVATE PTHREAD_PROCESS_PRIVATE
106 PTHREAD_PROCESS_SHARED
107#define PTHREAD_PROCESS_SHARED PTHREAD_PROCESS_SHARED
108};
109
110#if defined __USE_UNIX98 || defined __USE_XOPEN2K
111enum
112{
113 PTHREAD_RWLOCK_PREFER_READER_NP,
114 PTHREAD_RWLOCK_PREFER_WRITER_NP,
115 PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP,
116 PTHREAD_RWLOCK_DEFAULT_NP = PTHREAD_RWLOCK_PREFER_WRITER_NP
117};
118#endif /* Unix98 */
119
120#define PTHREAD_ONCE_INIT 0
121
122/* Special constants */
123
124#ifdef __USE_XOPEN2K
125/* -1 is distinct from 0 and all errno constants */
126# define PTHREAD_BARRIER_SERIAL_THREAD -1
127#endif
128
129/* Cleanup buffers */
130
131struct _pthread_cleanup_buffer
132{
133 void (*__routine) (void *); /* Function to call. */
134 void *__arg; /* Its argument. */
135 int __canceltype; /* Saved cancellation type. */
136 struct _pthread_cleanup_buffer *__prev; /* Chaining of cleanup functions. */
137};
138
139/* Cancellation */
140
141enum
142{
143 PTHREAD_CANCEL_ENABLE,
144#define PTHREAD_CANCEL_ENABLE PTHREAD_CANCEL_ENABLE
145 PTHREAD_CANCEL_DISABLE
146#define PTHREAD_CANCEL_DISABLE PTHREAD_CANCEL_DISABLE
147};
148enum
149{
150 PTHREAD_CANCEL_DEFERRED,
151#define PTHREAD_CANCEL_DEFERRED PTHREAD_CANCEL_DEFERRED
152 PTHREAD_CANCEL_ASYNCHRONOUS
153#define PTHREAD_CANCEL_ASYNCHRONOUS PTHREAD_CANCEL_ASYNCHRONOUS
154};
155#define PTHREAD_CANCELED ((void *) -1)
156
157
158/* Function for handling threads. */
159
160/* Create a thread with given attributes ATTR (or default attributes
161 if ATTR is NULL), and call function START_ROUTINE with given
162 arguments ARG. */
163extern int pthread_create (pthread_t *__restrict __threadp,
164 __const pthread_attr_t *__restrict __attr,
165 void *(*__start_routine) (void *),
166 void *__restrict __arg) __THROW;
167
168/* Obtain the identifier of the current thread. */
169extern pthread_t pthread_self (void) __THROW;
170
171/* Compare two thread identifiers. */
172extern int pthread_equal (pthread_t __thread1, pthread_t __thread2) __THROW;
173
174/* Terminate calling thread. */
175extern void pthread_exit (void *__retval) __attribute__ ((__noreturn__));
176
177/* Make calling thread wait for termination of the thread TH. The
178 exit status of the thread is stored in *THREAD_RETURN, if THREAD_RETURN
179 is not NULL. */
180extern int pthread_join (pthread_t __th, void **__thread_return);
181
182/* Indicate that the thread TH is never to be joined with PTHREAD_JOIN.
183 The resources of TH will therefore be freed immediately when it
184 terminates, instead of waiting for another thread to perform PTHREAD_JOIN
185 on it. */
186extern int pthread_detach (pthread_t __th) __THROW;
187
188
189/* Functions for handling attributes. */
190
191/* Initialize thread attribute *ATTR with default attributes
192 (detachstate is PTHREAD_JOINABLE, scheduling policy is SCHED_OTHER,
193 no user-provided stack). */
194extern int pthread_attr_init (pthread_attr_t *__attr) __THROW;
195
196/* Destroy thread attribute *ATTR. */
197extern int pthread_attr_destroy (pthread_attr_t *__attr) __THROW;
198
199/* Set the `detachstate' attribute in *ATTR according to DETACHSTATE. */
200extern int pthread_attr_setdetachstate (pthread_attr_t *__attr,
201 int __detachstate) __THROW;
202
203/* Return in *DETACHSTATE the `detachstate' attribute in *ATTR. */
204extern int pthread_attr_getdetachstate (__const pthread_attr_t *__attr,
205 int *__detachstate) __THROW;
206
207/* Set scheduling parameters (priority, etc) in *ATTR according to PARAM. */
208extern int pthread_attr_setschedparam (pthread_attr_t *__restrict __attr,
209 __const struct sched_param *__restrict
210 __param) __THROW;
211
212/* Return in *PARAM the scheduling parameters of *ATTR. */
213extern int pthread_attr_getschedparam (__const pthread_attr_t *__restrict
214 __attr,
215 struct sched_param *__restrict __param)
216 __THROW;
217
218/* Set scheduling policy in *ATTR according to POLICY. */
219extern int pthread_attr_setschedpolicy (pthread_attr_t *__attr, int __policy)
220 __THROW;
221
222/* Return in *POLICY the scheduling policy of *ATTR. */
223extern int pthread_attr_getschedpolicy (__const pthread_attr_t *__restrict
224 __attr, int *__restrict __policy)
225 __THROW;
226
227/* Set scheduling inheritance mode in *ATTR according to INHERIT. */
228extern int pthread_attr_setinheritsched (pthread_attr_t *__attr,
229 int __inherit) __THROW;
230
231/* Return in *INHERIT the scheduling inheritance mode of *ATTR. */
232extern int pthread_attr_getinheritsched (__const pthread_attr_t *__restrict
233 __attr, int *__restrict __inherit)
234 __THROW;
235
236/* Set scheduling contention scope in *ATTR according to SCOPE. */
237extern int pthread_attr_setscope (pthread_attr_t *__attr, int __scope)
238 __THROW;
239
240/* Return in *SCOPE the scheduling contention scope of *ATTR. */
241extern int pthread_attr_getscope (__const pthread_attr_t *__restrict __attr,
242 int *__restrict __scope) __THROW;
243
244#ifdef __USE_UNIX98
245/* Set the size of the guard area at the bottom of the thread. */
246extern int pthread_attr_setguardsize (pthread_attr_t *__attr,
247 size_t __guardsize) __THROW;
248
249/* Get the size of the guard area at the bottom of the thread. */
250extern int pthread_attr_getguardsize (__const pthread_attr_t *__restrict
251 __attr, size_t *__restrict __guardsize)
252 __THROW;
253#endif
254
255#if 0 /* uClibc: deprecated stuff disabled. def __UCLIBC_SUSV3_LEGACY__ */
256/* Set the starting address of the stack of the thread to be created.
257 Depending on whether the stack grows up or down the value must either
258 be higher or lower than all the address in the memory block. The
259 minimal size of the block must be PTHREAD_STACK_SIZE. */
260extern int pthread_attr_setstackaddr (pthread_attr_t *__attr,
261 void *__stackaddr) __THROW;
262
263/* Return the previously set address for the stack. */
264extern int pthread_attr_getstackaddr (__const pthread_attr_t *__restrict
265 __attr, void **__restrict __stackaddr)
266 __THROW;
267#endif
268
269#ifdef __USE_XOPEN2K
270/* The following two interfaces are intended to replace the last two. They
271 require setting the address as well as the size since only setting the
272 address will make the implementation on some architectures impossible. */
273extern int pthread_attr_setstack (pthread_attr_t *__attr, void *__stackaddr,
274 size_t __stacksize) __THROW;
275
276/* Return the previously set address for the stack. */
277extern int pthread_attr_getstack (__const pthread_attr_t *__restrict __attr,
278 void **__restrict __stackaddr,
279 size_t *__restrict __stacksize) __THROW;
280#endif
281
282/* Add information about the minimum stack size needed for the thread
283 to be started. This size must never be less than PTHREAD_STACK_SIZE
284 and must also not exceed the system limits. */
285extern int pthread_attr_setstacksize (pthread_attr_t *__attr,
286 size_t __stacksize) __THROW;
287
288/* Return the currently used minimal stack size. */
289extern int pthread_attr_getstacksize (__const pthread_attr_t *__restrict
290 __attr, size_t *__restrict __stacksize)
291 __THROW;
292
293#if 0
294/* Not yet implemented in uClibc! */
295
296#ifdef __USE_GNU
297/* Initialize thread attribute *ATTR with attributes corresponding to the
298 already running thread TH. It shall be called on uninitialized ATTR
299 and destroyed with pthread_attr_destroy when no longer needed. */
300extern int pthread_getattr_np (pthread_t __th, pthread_attr_t *__attr) __THROW;
301#endif
302#endif
303
304/* Functions for scheduling control. */
305
306/* Set the scheduling parameters for TARGET_THREAD according to POLICY
307 and *PARAM. */
308extern int pthread_setschedparam (pthread_t __target_thread, int __policy,
309 __const struct sched_param *__param)
310 __THROW;
311
312/* Return in *POLICY and *PARAM the scheduling parameters for TARGET_THREAD. */
313extern int pthread_getschedparam (pthread_t __target_thread,
314 int *__restrict __policy,
315 struct sched_param *__restrict __param)
316 __THROW;
317
318#ifdef __USE_UNIX98
319/* Determine level of concurrency. */
320extern int pthread_getconcurrency (void) __THROW;
321
322/* Set new concurrency level to LEVEL. */
323extern int pthread_setconcurrency (int __level) __THROW;
324#endif
325
326#ifdef __USE_GNU
327/* Same thing, different name */
328#define pthread_yield() sched_yield()
329#endif
330
331/* Functions for mutex handling. */
332
333/* Initialize MUTEX using attributes in *MUTEX_ATTR, or use the
334 default values if later is NULL. */
335extern int pthread_mutex_init (pthread_mutex_t *__restrict __mutex,
336 __const pthread_mutexattr_t *__restrict
337 __mutex_attr) __THROW;
338
339/* Destroy MUTEX. */
340extern int pthread_mutex_destroy (pthread_mutex_t *__mutex) __THROW;
341
342/* Try to lock MUTEX. */
343extern int pthread_mutex_trylock (pthread_mutex_t *__mutex) __THROW;
344
345/* Wait until lock for MUTEX becomes available and lock it. */
346extern int pthread_mutex_lock (pthread_mutex_t *__mutex) __THROW;
347
348#ifdef __USE_XOPEN2K
349/* Wait until lock becomes available, or specified time passes. */
350extern int pthread_mutex_timedlock (pthread_mutex_t *__restrict __mutex,
351 __const struct timespec *__restrict
352 __abstime) __THROW;
353#endif
354
355/* Unlock MUTEX. */
356extern int pthread_mutex_unlock (pthread_mutex_t *__mutex) __THROW;
357
358
359/* Functions for handling mutex attributes. */
360
361/* Initialize mutex attribute object ATTR with default attributes
362 (kind is PTHREAD_MUTEX_TIMED_NP). */
363extern int pthread_mutexattr_init (pthread_mutexattr_t *__attr) __THROW;
364
365/* Destroy mutex attribute object ATTR. */
366extern int pthread_mutexattr_destroy (pthread_mutexattr_t *__attr) __THROW;
367
368/* Get the process-shared flag of the mutex attribute ATTR. */
369extern int pthread_mutexattr_getpshared (__const pthread_mutexattr_t *
370 __restrict __attr,
371 int *__restrict __pshared) __THROW;
372
373/* Set the process-shared flag of the mutex attribute ATTR. */
374extern int pthread_mutexattr_setpshared (pthread_mutexattr_t *__attr,
375 int __pshared) __THROW;
376
377#ifdef __USE_UNIX98
378/* Set the mutex kind attribute in *ATTR to KIND (either PTHREAD_MUTEX_NORMAL,
379 PTHREAD_MUTEX_RECURSIVE, PTHREAD_MUTEX_ERRORCHECK, or
380 PTHREAD_MUTEX_DEFAULT). */
381extern int pthread_mutexattr_settype (pthread_mutexattr_t *__attr, int __kind)
382 __THROW;
383
384/* Return in *KIND the mutex kind attribute in *ATTR. */
385extern int pthread_mutexattr_gettype (__const pthread_mutexattr_t *__restrict
386 __attr, int *__restrict __kind) __THROW;
387#endif
388
389
390/* Functions for handling conditional variables. */
391
392/* Initialize condition variable COND using attributes ATTR, or use
393 the default values if later is NULL. */
394extern int pthread_cond_init (pthread_cond_t *__restrict __cond,
395 __const pthread_condattr_t *__restrict
396 __cond_attr) __THROW;
397
398/* Destroy condition variable COND. */
399extern int pthread_cond_destroy (pthread_cond_t *__cond) __THROW;
400
401/* Wake up one thread waiting for condition variable COND. */
402extern int pthread_cond_signal (pthread_cond_t *__cond) __THROW;
403
404/* Wake up all threads waiting for condition variables COND. */
405extern int pthread_cond_broadcast (pthread_cond_t *__cond) __THROW;
406
407/* Wait for condition variable COND to be signaled or broadcast.
408 MUTEX is assumed to be locked before. */
409extern int pthread_cond_wait (pthread_cond_t *__restrict __cond,
410 pthread_mutex_t *__restrict __mutex);
411
412/* Wait for condition variable COND to be signaled or broadcast until
413 ABSTIME. MUTEX is assumed to be locked before. ABSTIME is an
414 absolute time specification; zero is the beginning of the epoch
415 (00:00:00 GMT, January 1, 1970). */
416extern int pthread_cond_timedwait (pthread_cond_t *__restrict __cond,
417 pthread_mutex_t *__restrict __mutex,
418 __const struct timespec *__restrict
419 __abstime);
420
421/* Functions for handling condition variable attributes. */
422
423/* Initialize condition variable attribute ATTR. */
424extern int pthread_condattr_init (pthread_condattr_t *__attr) __THROW;
425
426/* Destroy condition variable attribute ATTR. */
427extern int pthread_condattr_destroy (pthread_condattr_t *__attr) __THROW;
428
429/* Get the process-shared flag of the condition variable attribute ATTR. */
430extern int pthread_condattr_getpshared (__const pthread_condattr_t *
431 __restrict __attr,
432 int *__restrict __pshared) __THROW;
433
434/* Set the process-shared flag of the condition variable attribute ATTR. */
435extern int pthread_condattr_setpshared (pthread_condattr_t *__attr,
436 int __pshared) __THROW;
437
438
439#if defined __USE_UNIX98 || defined __USE_XOPEN2K
440/* Functions for handling read-write locks. */
441
442/* Initialize read-write lock RWLOCK using attributes ATTR, or use
443 the default values if later is NULL. */
444extern int pthread_rwlock_init (pthread_rwlock_t *__restrict __rwlock,
445 __const pthread_rwlockattr_t *__restrict
446 __attr) __THROW;
447
448/* Destroy read-write lock RWLOCK. */
449extern int pthread_rwlock_destroy (pthread_rwlock_t *__rwlock) __THROW;
450
451/* Acquire read lock for RWLOCK. */
452extern int pthread_rwlock_rdlock (pthread_rwlock_t *__rwlock) __THROW;
453
454/* Try to acquire read lock for RWLOCK. */
455extern int pthread_rwlock_tryrdlock (pthread_rwlock_t *__rwlock) __THROW;
456
457# ifdef __USE_XOPEN2K
458/* Try to acquire read lock for RWLOCK or return after specfied time. */
459extern int pthread_rwlock_timedrdlock (pthread_rwlock_t *__restrict __rwlock,
460 __const struct timespec *__restrict
461 __abstime) __THROW;
462# endif
463
464/* Acquire write lock for RWLOCK. */
465extern int pthread_rwlock_wrlock (pthread_rwlock_t *__rwlock) __THROW;
466
467/* Try to acquire write lock for RWLOCK. */
468extern int pthread_rwlock_trywrlock (pthread_rwlock_t *__rwlock) __THROW;
469
470# ifdef __USE_XOPEN2K
471/* Try to acquire write lock for RWLOCK or return after specfied time. */
472extern int pthread_rwlock_timedwrlock (pthread_rwlock_t *__restrict __rwlock,
473 __const struct timespec *__restrict
474 __abstime) __THROW;
475# endif
476
477/* Unlock RWLOCK. */
478extern int pthread_rwlock_unlock (pthread_rwlock_t *__rwlock) __THROW;
479
480
481/* Functions for handling read-write lock attributes. */
482
483/* Initialize attribute object ATTR with default values. */
484extern int pthread_rwlockattr_init (pthread_rwlockattr_t *__attr) __THROW;
485
486/* Destroy attribute object ATTR. */
487extern int pthread_rwlockattr_destroy (pthread_rwlockattr_t *__attr) __THROW;
488
489/* Return current setting of process-shared attribute of ATTR in PSHARED. */
490extern int pthread_rwlockattr_getpshared (__const pthread_rwlockattr_t *
491 __restrict __attr,
492 int *__restrict __pshared) __THROW;
493
494/* Set process-shared attribute of ATTR to PSHARED. */
495extern int pthread_rwlockattr_setpshared (pthread_rwlockattr_t *__attr,
496 int __pshared) __THROW;
497
498/* Return current setting of reader/writer preference. */
499extern int pthread_rwlockattr_getkind_np (__const pthread_rwlockattr_t *__attr,
500 int *__pref) __THROW;
501
502/* Set reader/write preference. */
503extern int pthread_rwlockattr_setkind_np (pthread_rwlockattr_t *__attr,
504 int __pref) __THROW;
505#endif
506
507#if 0
508/* Not yet implemented in uClibc! */
509
510#ifdef __USE_XOPEN2K
511/* The IEEE Std. 1003.1j-2000 introduces functions to implement
512 spinlocks. */
513
514/* Initialize the spinlock LOCK. If PSHARED is nonzero the spinlock can
515 be shared between different processes. */
516extern int pthread_spin_init (pthread_spinlock_t *__lock, int __pshared)
517 __THROW;
518
519/* Destroy the spinlock LOCK. */
520extern int pthread_spin_destroy (pthread_spinlock_t *__lock) __THROW;
521
522/* Wait until spinlock LOCK is retrieved. */
523extern int pthread_spin_lock (pthread_spinlock_t *__lock) __THROW;
524
525/* Try to lock spinlock LOCK. */
526extern int pthread_spin_trylock (pthread_spinlock_t *__lock) __THROW;
527
528/* Release spinlock LOCK. */
529extern int pthread_spin_unlock (pthread_spinlock_t *__lock) __THROW;
530
531
532/* Barriers are a also a new feature in 1003.1j-2000. */
533
534extern int pthread_barrier_init (pthread_barrier_t *__restrict __barrier,
535 __const pthread_barrierattr_t *__restrict
536 __attr, unsigned int __count) __THROW;
537
538extern int pthread_barrier_destroy (pthread_barrier_t *__barrier) __THROW;
539
540extern int pthread_barrierattr_init (pthread_barrierattr_t *__attr) __THROW;
541
542extern int pthread_barrierattr_destroy (pthread_barrierattr_t *__attr) __THROW;
543
544extern int pthread_barrierattr_getpshared (__const pthread_barrierattr_t *
545 __restrict __attr,
546 int *__restrict __pshared) __THROW;
547
548extern int pthread_barrierattr_setpshared (pthread_barrierattr_t *__attr,
549 int __pshared) __THROW;
550
551extern int pthread_barrier_wait (pthread_barrier_t *__barrier) __THROW;
552#endif
553#endif
554
555
556/* Functions for handling thread-specific data. */
557
558/* Create a key value identifying a location in the thread-specific
559 data area. Each thread maintains a distinct thread-specific data
560 area. DESTR_FUNCTION, if non-NULL, is called with the value
561 associated to that key when the key is destroyed.
562 DESTR_FUNCTION is not called if the value associated is NULL when
563 the key is destroyed. */
564extern int pthread_key_create (pthread_key_t *__key,
565 void (*__destr_function) (void *)) __THROW;
566
567/* Destroy KEY. */
568extern int pthread_key_delete (pthread_key_t __key) __THROW;
569
570/* Store POINTER in the thread-specific data slot identified by KEY. */
571extern int pthread_setspecific (pthread_key_t __key,
572 __const void *__pointer) __THROW;
573
574/* Return current value of the thread-specific data slot identified by KEY. */
575extern void *pthread_getspecific (pthread_key_t __key) __THROW;
576
577
578/* Functions for handling initialization. */
579
580/* Guarantee that the initialization function INIT_ROUTINE will be called
581 only once, even if pthread_once is executed several times with the
582 same ONCE_CONTROL argument. ONCE_CONTROL must point to a static or
583 extern variable initialized to PTHREAD_ONCE_INIT.
584
585 The initialization functions might throw exception which is why
586 this function is not marked with __THROW. */
587extern int pthread_once (pthread_once_t *__once_control,
588 void (*__init_routine) (void));
589
590
591/* Functions for handling cancellation. */
592
593/* Set cancelability state of current thread to STATE, returning old
594 state in *OLDSTATE if OLDSTATE is not NULL. */
595extern int pthread_setcancelstate (int __state, int *__oldstate);
596
597/* Set cancellation state of current thread to TYPE, returning the old
598 type in *OLDTYPE if OLDTYPE is not NULL. */
599extern int pthread_setcanceltype (int __type, int *__oldtype);
600
601/* Cancel THREAD immediately or at the next possibility. */
602extern int pthread_cancel (pthread_t __cancelthread);
603
604/* Test for pending cancellation for the current thread and terminate
605 the thread as per pthread_exit(PTHREAD_CANCELED) if it has been
606 cancelled. */
607extern void pthread_testcancel (void);
608
609
610/* Install a cleanup handler: ROUTINE will be called with arguments ARG
611 when the thread is cancelled or calls pthread_exit. ROUTINE will also
612 be called with arguments ARG when the matching pthread_cleanup_pop
613 is executed with non-zero EXECUTE argument.
614 pthread_cleanup_push and pthread_cleanup_pop are macros and must always
615 be used in matching pairs at the same nesting level of braces. */
616
617#define pthread_cleanup_push(routine,arg) \
618 { struct _pthread_cleanup_buffer _buffer; \
619 _pthread_cleanup_push (&_buffer, (routine), (arg));
620
621extern void _pthread_cleanup_push (struct _pthread_cleanup_buffer *__buffer,
622 void (*__routine) (void *),
623 void *__arg) __THROW;
624
625/* Remove a cleanup handler installed by the matching pthread_cleanup_push.
626 If EXECUTE is non-zero, the handler function is called. */
627
628#define pthread_cleanup_pop(execute) \
629 _pthread_cleanup_pop (&_buffer, (execute)); }
630
631extern void _pthread_cleanup_pop (struct _pthread_cleanup_buffer *__buffer,
632 int __execute) __THROW;
633
634/* Install a cleanup handler as pthread_cleanup_push does, but also
635 saves the current cancellation type and set it to deferred cancellation. */
636
637#ifdef __USE_GNU
638# define pthread_cleanup_push_defer_np(routine,arg) \
639 { struct _pthread_cleanup_buffer _buffer; \
640 _pthread_cleanup_push_defer (&_buffer, (routine), (arg));
641
642extern void _pthread_cleanup_push_defer (struct _pthread_cleanup_buffer *__buffer,
643 void (*__routine) (void *),
644 void *__arg) __THROW;
645extern void __pthread_cleanup_push_defer (struct _pthread_cleanup_buffer *__buffer,
646 void (*__routine) (void *),
647 void *__arg) __THROW;
648
649/* Remove a cleanup handler as pthread_cleanup_pop does, but also
650 restores the cancellation type that was in effect when the matching
651 pthread_cleanup_push_defer was called. */
652
653# define pthread_cleanup_pop_restore_np(execute) \
654 _pthread_cleanup_pop_restore (&_buffer, (execute)); }
655
656extern void _pthread_cleanup_pop_restore (struct _pthread_cleanup_buffer *__buffer,
657 int __execute) __THROW;
658extern void __pthread_cleanup_pop_restore (struct _pthread_cleanup_buffer *__buffer,
659 int __execute) __THROW;
660#endif
661
662
663#if 0
664/* Not yet implemented in uClibc! */
665
666#ifdef __USE_XOPEN2K
667/* Get ID of CPU-time clock for thread THREAD_ID. */
668extern int pthread_getcpuclockid (pthread_t __thread_id,
669 clockid_t *__clock_id) __THROW;
670#endif
671#endif
672
673
674/* Functions for handling signals. */
675#include <bits/sigthread.h>
676
677
678/* Functions for handling process creation and process execution. */
679
680/* Install handlers to be called when a new process is created with FORK.
681 The PREPARE handler is called in the parent process just before performing
682 FORK. The PARENT handler is called in the parent process just after FORK.
683 The CHILD handler is called in the child process. Each of the three
684 handlers can be NULL, meaning that no handler needs to be called at that
685 point.
686 PTHREAD_ATFORK can be called several times, in which case the PREPARE
687 handlers are called in LIFO order (last added with PTHREAD_ATFORK,
688 first called before FORK), and the PARENT and CHILD handlers are called
689 in FIFO (first added, first called). */
690
691extern int pthread_atfork (void (*__prepare) (void),
692 void (*__parent) (void),
693 void (*__child) (void)) __THROW;
694
695/* Terminate all threads in the program except the calling process.
696 Should be called just before invoking one of the exec*() functions. */
697
698extern void pthread_kill_other_threads_np (void) __THROW;
699
700__END_DECLS
701
702#endif /* pthread.h */