thr_private.h revision 158073
1/* 2 * Copyright (C) 2005 Daniel M. Eischen <deischen@freebsd.org> 3 * Copyright (c) 2005 David Xu <davidxu@freebsd.org> 4 * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>. 5 * 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice unmodified, this list of conditions, and the following 13 * disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * 29 * $FreeBSD: head/lib/libthr/thread/thr_private.h 158073 2006-04-27 08:18:23Z davidxu $ 30 */ 31 32#ifndef _THR_PRIVATE_H 33#define _THR_PRIVATE_H 34 35/* 36 * Include files. 37 */ 38#include <sys/types.h> 39#include <sys/time.h> 40#include <sys/cdefs.h> 41#include <sys/queue.h> 42#include <machine/atomic.h> 43#include <errno.h> 44#include <limits.h> 45#include <signal.h> 46#include <stddef.h> 47#include <stdio.h> 48#include <unistd.h> 49#include <ucontext.h> 50#include <sys/thr.h> 51#include <pthread.h> 52 53#ifndef __hidden 54#define __hidden __attribute__((visibility("hidden"))) 55#endif 56 57#include "pthread_md.h" 58#include "thr_umtx.h" 59#include "thread_db.h" 60 61typedef TAILQ_HEAD(pthreadlist, pthread) pthreadlist; 62typedef TAILQ_HEAD(atfork_head, pthread_atfork) atfork_head; 63 64/* Signal to do cancellation */ 65#define SIGCANCEL 32 66 67/* 68 * Kernel fatal error handler macro. 69 */ 70#define PANIC(string) _thread_exit(__FILE__,__LINE__,string) 71 72/* Output debug messages like this: */ 73#define stdout_debug(args...) _thread_printf(STDOUT_FILENO, ##args) 74#define stderr_debug(args...) _thread_printf(STDOUT_FILENO, ##args) 75 76#ifdef _PTHREADS_INVARIANTS 77#define THR_ASSERT(cond, msg) do { \ 78 if (__predict_false(!(cond))) \ 79 PANIC(msg); \ 80} while (0) 81#else 82#define THR_ASSERT(cond, msg) 83#endif 84 85#ifdef PIC 86# define STATIC_LIB_REQUIRE(name) 87#else 88# define STATIC_LIB_REQUIRE(name) __asm (".globl " #name) 89#endif 90 91#define TIMESPEC_ADD(dst, src, val) \ 92 do { \ 93 (dst)->tv_sec = (src)->tv_sec + (val)->tv_sec; \ 94 (dst)->tv_nsec = (src)->tv_nsec + (val)->tv_nsec; \ 95 if ((dst)->tv_nsec >= 1000000000) { \ 96 (dst)->tv_sec++; \ 97 (dst)->tv_nsec -= 1000000000; \ 98 } \ 99 } while (0) 100 101#define TIMESPEC_SUB(dst, src, val) \ 102 do { \ 103 (dst)->tv_sec = (src)->tv_sec - (val)->tv_sec; \ 104 (dst)->tv_nsec = (src)->tv_nsec - (val)->tv_nsec; \ 105 if ((dst)->tv_nsec < 0) { \ 106 (dst)->tv_sec--; \ 107 (dst)->tv_nsec += 1000000000; \ 108 } \ 109 } while (0) 110 111struct pthread_mutex { 112 /* 113 * Lock for accesses to this structure. 114 */ 115 volatile umtx_t m_lock; 116 enum pthread_mutextype m_type; 117 int m_protocol; 118 TAILQ_HEAD(mutex_head, pthread) m_queue; 119 struct pthread *m_owner; 120 long m_flags; 121 int m_count; 122 int m_refcount; 123 124 /* 125 * Used for priority inheritence and protection. 126 * 127 * m_prio - For priority inheritence, the highest active 128 * priority (threads locking the mutex inherit 129 * this priority). For priority protection, the 130 * ceiling priority of this mutex. 131 * m_saved_prio - mutex owners inherited priority before 132 * taking the mutex, restored when the owner 133 * unlocks the mutex. 134 */ 135 int m_prio; 136 int m_saved_prio; 137 138 /* 139 * Link for list of all mutexes a thread currently owns. 140 */ 141 TAILQ_ENTRY(pthread_mutex) m_qe; 142}; 143 144/* 145 * Flags for mutexes. 146 */ 147#define MUTEX_FLAGS_PRIVATE 0x01 148#define MUTEX_FLAGS_INITED 0x02 149#define MUTEX_FLAGS_BUSY 0x04 150 151struct pthread_mutex_attr { 152 enum pthread_mutextype m_type; 153 int m_protocol; 154 int m_ceiling; 155 long m_flags; 156}; 157 158#define PTHREAD_MUTEXATTR_STATIC_INITIALIZER \ 159 { PTHREAD_MUTEX_DEFAULT, PTHREAD_PRIO_NONE, 0, MUTEX_FLAGS_PRIVATE } 160 161struct pthread_cond { 162 /* 163 * Lock for accesses to this structure. 164 */ 165 volatile umtx_t c_lock; 166 volatile umtx_t c_seqno; 167 volatile int c_waiters; 168 volatile int c_wakeups; 169 int c_pshared; 170 int c_clockid; 171}; 172 173struct pthread_cond_attr { 174 int c_pshared; 175 int c_clockid; 176}; 177 178struct pthread_barrier { 179 volatile umtx_t b_lock; 180 volatile umtx_t b_cycle; 181 volatile int b_count; 182 volatile int b_waiters; 183}; 184 185struct pthread_barrierattr { 186 int pshared; 187}; 188 189struct pthread_spinlock { 190 volatile umtx_t s_lock; 191}; 192 193/* 194 * Flags for condition variables. 195 */ 196#define COND_FLAGS_PRIVATE 0x01 197#define COND_FLAGS_INITED 0x02 198#define COND_FLAGS_BUSY 0x04 199 200/* 201 * Cleanup definitions. 202 */ 203struct pthread_cleanup { 204 struct pthread_cleanup *next; 205 void (*routine)(void *args); 206 void *routine_arg; 207 int onstack; 208}; 209 210#define THR_CLEANUP_PUSH(td, func, arg) { \ 211 struct pthread_cleanup __cup; \ 212 \ 213 __cup.routine = func; \ 214 __cup.routine_arg = arg; \ 215 __cup.onstack = 1; \ 216 __cup.next = (td)->cleanup; \ 217 (td)->cleanup = &__cup; 218 219#define THR_CLEANUP_POP(td, exec) \ 220 (td)->cleanup = __cup.next; \ 221 if ((exec) != 0) \ 222 __cup.routine(__cup.routine_arg); \ 223} 224 225struct pthread_atfork { 226 TAILQ_ENTRY(pthread_atfork) qe; 227 void (*prepare)(void); 228 void (*parent)(void); 229 void (*child)(void); 230}; 231 232struct pthread_attr { 233 int sched_policy; 234 int sched_inherit; 235 int prio; 236 int suspend; 237#define THR_STACK_USER 0x100 /* 0xFF reserved for <pthread.h> */ 238 int flags; 239 void *stackaddr_attr; 240 size_t stacksize_attr; 241 size_t guardsize_attr; 242}; 243 244/* 245 * Thread creation state attributes. 246 */ 247#define THR_CREATE_RUNNING 0 248#define THR_CREATE_SUSPENDED 1 249 250/* 251 * Miscellaneous definitions. 252 */ 253#define THR_STACK_DEFAULT (sizeof(void *) / 4 * 1024 * 1024) 254 255/* 256 * Maximum size of initial thread's stack. This perhaps deserves to be larger 257 * than the stacks of other threads, since many applications are likely to run 258 * almost entirely on this stack. 259 */ 260#define THR_STACK_INITIAL (THR_STACK_DEFAULT * 2) 261 262/* 263 * Define priorities returned by kernel. 264 */ 265#define THR_MIN_PRIORITY (_thr_priorities[SCHED_OTHER-1].pri_min) 266#define THR_MAX_PRIORITY (_thr_priorities[SCHED_OTHER-1].pri_min) 267#define THR_DEF_PRIORITY (_thr_priorities[SCHED_OTHER-1].pri_default) 268 269#define THR_MIN_RR_PRIORITY (_thr_priorities[SCHED_RR-1].pri_min) 270#define THR_MAX_RR_PRIORITY (_thr_priorities[SCHED_RR-1].pri_max) 271#define THR_DEF_RR_PRIORITY (_thr_priorities[SCHED_RR-1].pri_default) 272 273/* XXX The SCHED_FIFO should have same priority range as SCHED_RR */ 274#define THR_MIN_FIFO_PRIORITY (_thr_priorities[SCHED_FIFO_1].pri_min) 275#define THR_MAX_FIFO_PRIORITY (_thr_priorities[SCHED_FIFO-1].pri_min) 276#define THR_DEF_FIFO_PRIORITY (_thr_priorities[SCHED_FIFO-1].pri_default) 277 278struct pthread_prio { 279 int pri_min; 280 int pri_max; 281 int pri_default; 282}; 283 284struct pthread_rwlockattr { 285 int pshared; 286}; 287 288struct pthread_rwlock { 289 pthread_mutex_t lock; /* monitor lock */ 290 pthread_cond_t read_signal; 291 pthread_cond_t write_signal; 292 int state; /* 0 = idle >0 = # of readers -1 = writer */ 293 int blocked_writers; 294}; 295 296/* 297 * Thread states. 298 */ 299enum pthread_state { 300 PS_RUNNING, 301 PS_DEAD 302}; 303 304struct pthread_specific_elem { 305 const void *data; 306 int seqno; 307}; 308 309struct pthread_key { 310 volatile int allocated; 311 volatile int count; 312 int seqno; 313 void (*destructor)(void *); 314}; 315 316/* 317 * Thread structure. 318 */ 319struct pthread { 320 /* Kernel thread id. */ 321 long tid; 322#define TID_TERMINATED 1 323 324 /* 325 * Lock for accesses to this thread structure. 326 */ 327 umtx_t lock; 328 329 /* Internal condition variable cycle number. */ 330 umtx_t cycle; 331 332 /* How many low level locks the thread held. */ 333 int locklevel; 334 335 /* 336 * Set to non-zero when this thread has entered a critical 337 * region. We allow for recursive entries into critical regions. 338 */ 339 int critical_count; 340 341 /* Signal blocked counter. */ 342 int sigblock; 343 344 /* Queue entry for list of all threads. */ 345 TAILQ_ENTRY(pthread) tle; /* link for all threads in process */ 346 347 /* Queue entry for GC lists. */ 348 TAILQ_ENTRY(pthread) gcle; 349 350 /* Hash queue entry. */ 351 LIST_ENTRY(pthread) hle; 352 353 /* Threads reference count. */ 354 int refcount; 355 356 /* 357 * Thread start routine, argument, stack pointer and thread 358 * attributes. 359 */ 360 void *(*start_routine)(void *); 361 void *arg; 362 struct pthread_attr attr; 363 364 /* 365 * Cancelability flags 366 */ 367#define THR_CANCEL_DISABLE 0x0001 368#define THR_CANCEL_EXITING 0x0002 369#define THR_CANCEL_AT_POINT 0x0004 370#define THR_CANCEL_NEEDED 0x0008 371#define SHOULD_CANCEL(val) \ 372 (((val) & (THR_CANCEL_DISABLE | THR_CANCEL_EXITING | \ 373 THR_CANCEL_NEEDED)) == THR_CANCEL_NEEDED) 374 375#define SHOULD_ASYNC_CANCEL(val) \ 376 (((val) & (THR_CANCEL_DISABLE | THR_CANCEL_EXITING | \ 377 THR_CANCEL_NEEDED | THR_CANCEL_AT_POINT)) == \ 378 (THR_CANCEL_NEEDED | THR_CANCEL_AT_POINT)) 379 int cancelflags; 380 381 /* Thread temporary signal mask. */ 382 sigset_t sigmask; 383 384 /* Thread state: */ 385 umtx_t state; 386 387 /* 388 * Error variable used instead of errno. The function __error() 389 * returns a pointer to this. 390 */ 391 int error; 392 393 /* 394 * The joiner is the thread that is joining to this thread. The 395 * join status keeps track of a join operation to another thread. 396 */ 397 struct pthread *joiner; 398 399 /* 400 * The current thread can belong to a priority mutex queue. 401 * This is the synchronization queue link. 402 */ 403 TAILQ_ENTRY(pthread) sqe; 404 405 /* Miscellaneous flags; only set with scheduling lock held. */ 406 int flags; 407#define THR_FLAGS_PRIVATE 0x0001 408#define THR_FLAGS_NEED_SUSPEND 0x0002 /* thread should be suspended */ 409#define THR_FLAGS_SUSPENDED 0x0004 /* thread is suspended */ 410 411 /* Thread list flags; only set with thread list lock held. */ 412 int tlflags; 413#define TLFLAGS_GC_SAFE 0x0001 /* thread safe for cleaning */ 414#define TLFLAGS_IN_TDLIST 0x0002 /* thread in all thread list */ 415#define TLFLAGS_IN_GCLIST 0x0004 /* thread in gc list */ 416#define TLFLAGS_DETACHED 0x0008 /* thread is detached */ 417 418 /* 419 * Base priority is the user setable and retrievable priority 420 * of the thread. It is only affected by explicit calls to 421 * set thread priority and upon thread creation via a thread 422 * attribute or default priority. 423 */ 424 char base_priority; 425 426 /* 427 * Inherited priority is the priority a thread inherits by 428 * taking a priority inheritence or protection mutex. It 429 * is not affected by base priority changes. Inherited 430 * priority defaults to and remains 0 until a mutex is taken 431 * that is being waited on by any other thread whose priority 432 * is non-zero. 433 */ 434 char inherited_priority; 435 436 /* 437 * Active priority is always the maximum of the threads base 438 * priority and inherited priority. When there is a change 439 * in either the base or inherited priority, the active 440 * priority must be recalculated. 441 */ 442 char active_priority; 443 444 /* Queue of currently owned simple type mutexes. */ 445 TAILQ_HEAD(, pthread_mutex) mutexq; 446 447 void *ret; 448 struct pthread_specific_elem *specific; 449 int specific_data_count; 450 451 /* Number rwlocks rdlocks held. */ 452 int rdlock_count; 453 454 /* 455 * Current locks bitmap for rtld. */ 456 int rtld_bits; 457 458 /* Thread control block */ 459 struct tcb *tcb; 460 461 /* Cleanup handlers Link List */ 462 struct pthread_cleanup *cleanup; 463 464 /* 465 * Magic value to help recognize a valid thread structure 466 * from an invalid one: 467 */ 468#define THR_MAGIC ((u_int32_t) 0xd09ba115) 469 u_int32_t magic; 470 471 /* Enable event reporting */ 472 int report_events; 473 474 /* Event mask */ 475 int event_mask; 476 477 /* Event */ 478 td_event_msg_t event_buf; 479}; 480 481#define THR_IN_CRITICAL(thrd) \ 482 (((thrd)->locklevel > 0) || \ 483 ((thrd)->critical_count > 0)) 484 485#define THR_CRITICAL_ENTER(thrd) \ 486 (thrd)->critical_count++ 487 488#define THR_CRITICAL_LEAVE(thrd) \ 489 (thrd)->critical_count--; \ 490 _thr_ast(thrd); 491 492#define THR_UMTX_TRYLOCK(thrd, lck) \ 493 _thr_umtx_trylock((lck), (thrd)->tid) 494 495#define THR_UMTX_LOCK(thrd, lck) \ 496 _thr_umtx_lock((lck), (thrd)->tid) 497 498#define THR_UMTX_TIMEDLOCK(thrd, lck, timo) \ 499 _thr_umtx_timedlock((lck), (thrd)->tid, (timo)) 500 501#define THR_UMTX_UNLOCK(thrd, lck) \ 502 _thr_umtx_unlock((lck), (thrd)->tid) 503 504#define THR_LOCK_ACQUIRE(thrd, lck) \ 505do { \ 506 (thrd)->locklevel++; \ 507 _thr_umtx_lock(lck, (thrd)->tid); \ 508} while (0) 509 510#ifdef _PTHREADS_INVARIANTS 511#define THR_ASSERT_LOCKLEVEL(thrd) \ 512do { \ 513 if (__predict_false((thrd)->locklevel <= 0)) \ 514 _thr_assert_lock_level(); \ 515} while (0) 516#else 517#define THR_ASSERT_LOCKLEVEL(thrd) 518#endif 519 520#define THR_LOCK_RELEASE(thrd, lck) \ 521do { \ 522 THR_ASSERT_LOCKLEVEL(thrd); \ 523 _thr_umtx_unlock((lck), (thrd)->tid); \ 524 (thrd)->locklevel--; \ 525 _thr_ast(thrd); \ 526} while (0) 527 528#define THR_LOCK(curthrd) THR_LOCK_ACQUIRE(curthrd, &(curthrd)->lock) 529#define THR_UNLOCK(curthrd) THR_LOCK_RELEASE(curthrd, &(curthrd)->lock) 530#define THR_THREAD_LOCK(curthrd, thr) THR_LOCK_ACQUIRE(curthrd, &(thr)->lock) 531#define THR_THREAD_UNLOCK(curthrd, thr) THR_LOCK_RELEASE(curthrd, &(thr)->lock) 532 533#define THREAD_LIST_LOCK(curthrd) \ 534do { \ 535 THR_LOCK_ACQUIRE((curthrd), &_thr_list_lock); \ 536} while (0) 537 538#define THREAD_LIST_UNLOCK(curthrd) \ 539do { \ 540 THR_LOCK_RELEASE((curthrd), &_thr_list_lock); \ 541} while (0) 542 543/* 544 * Macros to insert/remove threads to the all thread list and 545 * the gc list. 546 */ 547#define THR_LIST_ADD(thrd) do { \ 548 if (((thrd)->tlflags & TLFLAGS_IN_TDLIST) == 0) { \ 549 TAILQ_INSERT_HEAD(&_thread_list, thrd, tle); \ 550 _thr_hash_add(thrd); \ 551 (thrd)->tlflags |= TLFLAGS_IN_TDLIST; \ 552 } \ 553} while (0) 554#define THR_LIST_REMOVE(thrd) do { \ 555 if (((thrd)->tlflags & TLFLAGS_IN_TDLIST) != 0) { \ 556 TAILQ_REMOVE(&_thread_list, thrd, tle); \ 557 _thr_hash_remove(thrd); \ 558 (thrd)->tlflags &= ~TLFLAGS_IN_TDLIST; \ 559 } \ 560} while (0) 561#define THR_GCLIST_ADD(thrd) do { \ 562 if (((thrd)->tlflags & TLFLAGS_IN_GCLIST) == 0) { \ 563 TAILQ_INSERT_HEAD(&_thread_gc_list, thrd, gcle);\ 564 (thrd)->tlflags |= TLFLAGS_IN_GCLIST; \ 565 _gc_count++; \ 566 } \ 567} while (0) 568#define THR_GCLIST_REMOVE(thrd) do { \ 569 if (((thrd)->tlflags & TLFLAGS_IN_GCLIST) != 0) { \ 570 TAILQ_REMOVE(&_thread_gc_list, thrd, gcle); \ 571 (thrd)->tlflags &= ~TLFLAGS_IN_GCLIST; \ 572 _gc_count--; \ 573 } \ 574} while (0) 575 576#define GC_NEEDED() (_gc_count >= 5) 577 578#define SHOULD_REPORT_EVENT(curthr, e) \ 579 (curthr->report_events && \ 580 (((curthr)->event_mask | _thread_event_mask ) & e) != 0) 581 582extern int __isthreaded; 583 584/* 585 * Global variables for the pthread kernel. 586 */ 587 588extern char *_usrstack __hidden; 589extern struct pthread *_thr_initial __hidden; 590extern int _thr_scope_system __hidden; 591 592/* For debugger */ 593extern int _libthr_debug; 594extern int _thread_event_mask; 595extern struct pthread *_thread_last_event; 596 597/* List of all threads: */ 598extern pthreadlist _thread_list; 599 600/* List of threads needing GC: */ 601extern pthreadlist _thread_gc_list __hidden; 602 603extern int _thread_active_threads; 604extern atfork_head _thr_atfork_list __hidden; 605extern umtx_t _thr_atfork_lock __hidden; 606 607/* Default thread attributes: */ 608extern struct pthread_attr _pthread_attr_default __hidden; 609 610/* Default mutex attributes: */ 611extern struct pthread_mutex_attr _pthread_mutexattr_default __hidden; 612 613/* Default condition variable attributes: */ 614extern struct pthread_cond_attr _pthread_condattr_default __hidden; 615 616extern struct pthread_prio _thr_priorities[] __hidden; 617 618extern pid_t _thr_pid __hidden; 619extern size_t _thr_guard_default __hidden; 620extern size_t _thr_stack_default __hidden; 621extern size_t _thr_stack_initial __hidden; 622extern int _thr_page_size __hidden; 623/* Garbage thread count. */ 624extern int _gc_count __hidden; 625 626extern umtx_t _mutex_static_lock __hidden; 627extern umtx_t _cond_static_lock __hidden; 628extern umtx_t _rwlock_static_lock __hidden; 629extern umtx_t _keytable_lock __hidden; 630extern umtx_t _thr_list_lock __hidden; 631extern umtx_t _thr_event_lock __hidden; 632 633/* 634 * Function prototype definitions. 635 */ 636__BEGIN_DECLS 637int _thr_setthreaded(int) __hidden; 638int _mutex_cv_lock(pthread_mutex_t *, int count) __hidden; 639int _mutex_cv_unlock(pthread_mutex_t *, int *count) __hidden; 640int _mutex_reinit(pthread_mutex_t *) __hidden; 641void _mutex_fork(struct pthread *curthread) __hidden; 642void _mutex_unlock_private(struct pthread *) __hidden; 643void _libpthread_init(struct pthread *) __hidden; 644struct pthread *_thr_alloc(struct pthread *) __hidden; 645void _thread_exit(const char *, int, const char *) __hidden __dead2; 646void _thr_exit_cleanup(void) __hidden; 647int _thr_ref_add(struct pthread *, struct pthread *, int) __hidden; 648void _thr_ref_delete(struct pthread *, struct pthread *) __hidden; 649void _thr_ref_delete_unlocked(struct pthread *, struct pthread *) __hidden; 650int _thr_find_thread(struct pthread *, struct pthread *, int) __hidden; 651void _thr_rtld_init(void) __hidden; 652void _thr_rtld_fini(void) __hidden; 653int _thr_stack_alloc(struct pthread_attr *) __hidden; 654void _thr_stack_free(struct pthread_attr *) __hidden; 655void _thr_free(struct pthread *, struct pthread *) __hidden; 656void _thr_gc(struct pthread *) __hidden; 657void _thread_cleanupspecific(void) __hidden; 658void _thread_dump_info(void) __hidden; 659void _thread_printf(int, const char *, ...) __hidden; 660void _thr_spinlock_init(void) __hidden; 661int _thr_cancel_enter(struct pthread *) __hidden; 662void _thr_cancel_leave(struct pthread *, int) __hidden; 663void _thr_signal_block(struct pthread *) __hidden; 664void _thr_signal_unblock(struct pthread *) __hidden; 665void _thr_signal_init(void) __hidden; 666void _thr_signal_deinit(void) __hidden; 667int _thr_send_sig(struct pthread *, int sig) __hidden; 668void _thr_list_init(void) __hidden; 669void _thr_hash_add(struct pthread *) __hidden; 670void _thr_hash_remove(struct pthread *) __hidden; 671struct pthread *_thr_hash_find(struct pthread *) __hidden; 672void _thr_link(struct pthread *, struct pthread *) __hidden; 673void _thr_unlink(struct pthread *, struct pthread *) __hidden; 674void _thr_suspend_check(struct pthread *) __hidden; 675void _thr_assert_lock_level(void) __hidden __dead2; 676void _thr_ast(struct pthread *) __hidden; 677void _thr_once_init(void) __hidden; 678void _thr_report_creation(struct pthread *curthread, 679 struct pthread *newthread) __hidden; 680void _thr_report_death(struct pthread *curthread) __hidden; 681void _thread_bp_create(void); 682void _thread_bp_death(void); 683 684/* #include <fcntl.h> */ 685#ifdef _SYS_FCNTL_H_ 686int __sys_fcntl(int, int, ...); 687int __sys_open(const char *, int, ...); 688#endif 689 690/* #include <signal.h> */ 691#ifdef _SIGNAL_H_ 692int __sys_kill(pid_t, int); 693int __sys_sigaction(int, const struct sigaction *, struct sigaction *); 694int __sys_sigpending(sigset_t *); 695int __sys_sigprocmask(int, const sigset_t *, sigset_t *); 696int __sys_sigsuspend(const sigset_t *); 697int __sys_sigreturn(ucontext_t *); 698int __sys_sigaltstack(const struct sigaltstack *, struct sigaltstack *); 699int __sys_sigwait(const sigset_t *, int *); 700int __sys_sigtimedwait(const sigset_t *, siginfo_t *, 701 const struct timespec *); 702int __sys_sigwaitinfo(const sigset_t *set, siginfo_t *info); 703#endif 704 705/* #include <time.h> */ 706#ifdef _TIME_H_ 707int __sys_nanosleep(const struct timespec *, struct timespec *); 708#endif 709 710/* #include <unistd.h> */ 711#ifdef _UNISTD_H_ 712int __sys_close(int); 713int __sys_fork(void); 714pid_t __sys_getpid(void); 715ssize_t __sys_read(int, void *, size_t); 716ssize_t __sys_write(int, const void *, size_t); 717void __sys_exit(int); 718#endif 719 720static inline int 721_thr_isthreaded(void) 722{ 723 return (__isthreaded != 0); 724} 725 726static inline int 727_thr_is_inited(void) 728{ 729 return (_thr_initial != NULL); 730} 731 732static inline void 733_thr_check_init(void) 734{ 735 if (_thr_initial == NULL) 736 _libpthread_init(NULL); 737} 738 739__END_DECLS 740 741#endif /* !_THR_PRIVATE_H */ 742