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