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