OSDN Git Service

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