thr_private.h revision 212551
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 212551 2010-09-13 11:57:46Z 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 <sys/param.h> 43#include <sys/cpuset.h> 44#include <machine/atomic.h> 45#include <errno.h> 46#include <limits.h> 47#include <signal.h> 48#include <stddef.h> 49#include <stdio.h> 50#include <unistd.h> 51#include <ucontext.h> 52#include <sys/thr.h> 53#include <pthread.h> 54 55#define SYM_FB10(sym) __CONCAT(sym, _fb10) 56#define SYM_FBP10(sym) __CONCAT(sym, _fbp10) 57#define WEAK_REF(sym, alias) __weak_reference(sym, alias) 58#define SYM_COMPAT(sym, impl, ver) __sym_compat(sym, impl, ver) 59#define SYM_DEFAULT(sym, impl, ver) __sym_default(sym, impl, ver) 60 61#define FB10_COMPAT(func, sym) \ 62 WEAK_REF(func, SYM_FB10(sym)); \ 63 SYM_COMPAT(sym, SYM_FB10(sym), FBSD_1.0) 64 65#define FB10_COMPAT_PRIVATE(func, sym) \ 66 WEAK_REF(func, SYM_FBP10(sym)); \ 67 SYM_DEFAULT(sym, SYM_FBP10(sym), FBSDprivate_1.0) 68 69#include "pthread_md.h" 70#include "thr_umtx.h" 71#include "thread_db.h" 72 73typedef TAILQ_HEAD(pthreadlist, pthread) pthreadlist; 74typedef TAILQ_HEAD(atfork_head, pthread_atfork) atfork_head; 75TAILQ_HEAD(mutex_queue, pthread_mutex); 76 77/* Signal to do cancellation */ 78#define SIGCANCEL 32 79 80/* 81 * Kernel fatal error handler macro. 82 */ 83#define PANIC(string) _thread_exit(__FILE__,__LINE__,string) 84 85/* Output debug messages like this: */ 86#define stdout_debug(args...) _thread_printf(STDOUT_FILENO, ##args) 87#define stderr_debug(args...) _thread_printf(STDERR_FILENO, ##args) 88 89#ifdef _PTHREADS_INVARIANTS 90#define THR_ASSERT(cond, msg) do { \ 91 if (__predict_false(!(cond))) \ 92 PANIC(msg); \ 93} while (0) 94#else 95#define THR_ASSERT(cond, msg) 96#endif 97 98#ifdef PIC 99# define STATIC_LIB_REQUIRE(name) 100#else 101# define STATIC_LIB_REQUIRE(name) __asm (".globl " #name) 102#endif 103 104#define TIMESPEC_ADD(dst, src, val) \ 105 do { \ 106 (dst)->tv_sec = (src)->tv_sec + (val)->tv_sec; \ 107 (dst)->tv_nsec = (src)->tv_nsec + (val)->tv_nsec; \ 108 if ((dst)->tv_nsec >= 1000000000) { \ 109 (dst)->tv_sec++; \ 110 (dst)->tv_nsec -= 1000000000; \ 111 } \ 112 } while (0) 113 114#define TIMESPEC_SUB(dst, src, val) \ 115 do { \ 116 (dst)->tv_sec = (src)->tv_sec - (val)->tv_sec; \ 117 (dst)->tv_nsec = (src)->tv_nsec - (val)->tv_nsec; \ 118 if ((dst)->tv_nsec < 0) { \ 119 (dst)->tv_sec--; \ 120 (dst)->tv_nsec += 1000000000; \ 121 } \ 122 } while (0) 123 124struct pthread_mutex { 125 /* 126 * Lock for accesses to this structure. 127 */ 128 struct umutex m_lock; 129 enum pthread_mutextype m_type; 130 struct pthread *m_owner; 131 int m_count; 132 int m_refcount; 133 int m_spinloops; 134 int m_yieldloops; 135 int m_private; 136 /* 137 * Link for all mutexes a thread currently owns. 138 */ 139 TAILQ_ENTRY(pthread_mutex) m_qe; 140}; 141 142struct pthread_mutex_attr { 143 enum pthread_mutextype m_type; 144 int m_protocol; 145 int m_ceiling; 146}; 147 148#define PTHREAD_MUTEXATTR_STATIC_INITIALIZER \ 149 { PTHREAD_MUTEX_DEFAULT, PTHREAD_PRIO_NONE, 0, MUTEX_FLAGS_PRIVATE } 150 151struct pthread_cond { 152 struct umutex c_lock; 153 struct ucond c_kerncv; 154 int c_pshared; 155 int c_clockid; 156}; 157 158struct pthread_cond_attr { 159 int c_pshared; 160 int c_clockid; 161}; 162 163struct pthread_barrier { 164 struct umutex b_lock; 165 struct ucond b_cv; 166 volatile int64_t b_cycle; 167 volatile int b_count; 168 volatile int b_waiters; 169}; 170 171struct pthread_barrierattr { 172 int pshared; 173}; 174 175struct pthread_spinlock { 176 struct umutex s_lock; 177}; 178 179/* 180 * Flags for condition variables. 181 */ 182#define COND_FLAGS_PRIVATE 0x01 183#define COND_FLAGS_INITED 0x02 184#define COND_FLAGS_BUSY 0x04 185 186/* 187 * Cleanup definitions. 188 */ 189struct pthread_cleanup { 190 struct pthread_cleanup *prev; 191 void (*routine)(void *); 192 void *routine_arg; 193 int onheap; 194}; 195 196#define THR_CLEANUP_PUSH(td, func, arg) { \ 197 struct pthread_cleanup __cup; \ 198 \ 199 __cup.routine = func; \ 200 __cup.routine_arg = arg; \ 201 __cup.onheap = 0; \ 202 __cup.prev = (td)->cleanup; \ 203 (td)->cleanup = &__cup; 204 205#define THR_CLEANUP_POP(td, exec) \ 206 (td)->cleanup = __cup.prev; \ 207 if ((exec) != 0) \ 208 __cup.routine(__cup.routine_arg); \ 209} 210 211struct pthread_atfork { 212 TAILQ_ENTRY(pthread_atfork) qe; 213 void (*prepare)(void); 214 void (*parent)(void); 215 void (*child)(void); 216}; 217 218struct pthread_attr { 219 int sched_policy; 220 int sched_inherit; 221 int prio; 222 int suspend; 223#define THR_STACK_USER 0x100 /* 0xFF reserved for <pthread.h> */ 224 int flags; 225 void *stackaddr_attr; 226 size_t stacksize_attr; 227 size_t guardsize_attr; 228 cpuset_t *cpuset; 229 size_t cpusetsize; 230}; 231 232/* 233 * Thread creation state attributes. 234 */ 235#define THR_CREATE_RUNNING 0 236#define THR_CREATE_SUSPENDED 1 237 238/* 239 * Miscellaneous definitions. 240 */ 241#define THR_STACK_DEFAULT (sizeof(void *) / 4 * 1024 * 1024) 242 243/* 244 * Maximum size of initial thread's stack. This perhaps deserves to be larger 245 * than the stacks of other threads, since many applications are likely to run 246 * almost entirely on this stack. 247 */ 248#define THR_STACK_INITIAL (THR_STACK_DEFAULT * 2) 249 250/* 251 * Define priorities returned by kernel. 252 */ 253#define THR_MIN_PRIORITY (_thr_priorities[SCHED_OTHER-1].pri_min) 254#define THR_MAX_PRIORITY (_thr_priorities[SCHED_OTHER-1].pri_max) 255#define THR_DEF_PRIORITY (_thr_priorities[SCHED_OTHER-1].pri_default) 256 257#define THR_MIN_RR_PRIORITY (_thr_priorities[SCHED_RR-1].pri_min) 258#define THR_MAX_RR_PRIORITY (_thr_priorities[SCHED_RR-1].pri_max) 259#define THR_DEF_RR_PRIORITY (_thr_priorities[SCHED_RR-1].pri_default) 260 261/* XXX The SCHED_FIFO should have same priority range as SCHED_RR */ 262#define THR_MIN_FIFO_PRIORITY (_thr_priorities[SCHED_FIFO_1].pri_min) 263#define THR_MAX_FIFO_PRIORITY (_thr_priorities[SCHED_FIFO-1].pri_max) 264#define THR_DEF_FIFO_PRIORITY (_thr_priorities[SCHED_FIFO-1].pri_default) 265 266struct pthread_prio { 267 int pri_min; 268 int pri_max; 269 int pri_default; 270}; 271 272struct pthread_rwlockattr { 273 int pshared; 274}; 275 276struct pthread_rwlock { 277 struct urwlock lock; 278 struct pthread *owner; 279}; 280 281/* 282 * Thread states. 283 */ 284enum pthread_state { 285 PS_RUNNING, 286 PS_DEAD 287}; 288 289struct pthread_specific_elem { 290 const void *data; 291 int seqno; 292}; 293 294struct pthread_key { 295 volatile int allocated; 296 int seqno; 297 void (*destructor)(void *); 298}; 299 300/* 301 * lwpid_t is 32bit but kernel thr API exports tid as long type 302 * in very earily date. 303 */ 304#define TID(thread) ((uint32_t) ((thread)->tid)) 305 306/* 307 * Thread structure. 308 */ 309struct pthread { 310 /* Kernel thread id. */ 311 long tid; 312#define TID_TERMINATED 1 313 314 /* 315 * Lock for accesses to this thread structure. 316 */ 317 struct umutex lock; 318 319 /* Internal condition variable cycle number. */ 320 uint32_t cycle; 321 322 /* How many low level locks the thread held. */ 323 int locklevel; 324 325 /* 326 * Set to non-zero when this thread has entered a critical 327 * region. We allow for recursive entries into critical regions. 328 */ 329 int critical_count; 330 331 /* Signal blocked counter. */ 332 int sigblock; 333 334 /* Queue entry for list of all threads. */ 335 TAILQ_ENTRY(pthread) tle; /* link for all threads in process */ 336 337 /* Queue entry for GC lists. */ 338 TAILQ_ENTRY(pthread) gcle; 339 340 /* Hash queue entry. */ 341 LIST_ENTRY(pthread) hle; 342 343 /* Threads reference count. */ 344 int refcount; 345 346 /* 347 * Thread start routine, argument, stack pointer and thread 348 * attributes. 349 */ 350 void *(*start_routine)(void *); 351 void *arg; 352 struct pthread_attr attr; 353 354#define SHOULD_CANCEL(thr) \ 355 ((thr)->cancel_pending && \ 356 ((thr)->cancel_point || (thr)->cancel_async) && \ 357 (thr)->cancel_enable && (thr)->cancelling == 0) 358 359 /* Cancellation is enabled */ 360 int cancel_enable; 361 362 /* Cancellation request is pending */ 363 int cancel_pending; 364 365 /* Thread is at cancellation point */ 366 int cancel_point; 367 368 /* Cancellation should be synchoronized */ 369 int cancel_defer; 370 371 /* Asynchronouse cancellation is enabled */ 372 int cancel_async; 373 374 /* Cancellation is in progress */ 375 int cancelling; 376 377 /* Thread temporary signal mask. */ 378 sigset_t sigmask; 379 380 /* Thread should unblock SIGCANCEL. */ 381 int unblock_sigcancel; 382 383 /* In sigsuspend state */ 384 int in_sigsuspend; 385 386 /* deferred signal info */ 387 siginfo_t deferred_siginfo; 388 389 /* signal mask to restore. */ 390 sigset_t deferred_sigmask; 391 392 /* the sigaction should be used for deferred signal. */ 393 struct sigaction deferred_sigact; 394 395 /* Force new thread to exit. */ 396 int force_exit; 397 398 /* Thread state: */ 399 enum pthread_state state; 400 401 /* 402 * Error variable used instead of errno. The function __error() 403 * returns a pointer to this. 404 */ 405 int error; 406 407 /* 408 * The joiner is the thread that is joining to this thread. The 409 * join status keeps track of a join operation to another thread. 410 */ 411 struct pthread *joiner; 412 413 /* Miscellaneous flags; only set with scheduling lock held. */ 414 int flags; 415#define THR_FLAGS_PRIVATE 0x0001 416#define THR_FLAGS_NEED_SUSPEND 0x0002 /* thread should be suspended */ 417#define THR_FLAGS_SUSPENDED 0x0004 /* thread is suspended */ 418#define THR_FLAGS_IN_GCLIST 0x0008 /* thread in gc list */ 419#define THR_FLAGS_DETACHED 0x0010 /* thread is detached */ 420 421 /* Thread list flags; only set with thread list lock held. */ 422 int tlflags; 423#define TLFLAGS_GC_SAFE 0x0001 /* thread safe for cleaning */ 424#define TLFLAGS_IN_TDLIST 0x0002 /* thread in all thread list */ 425 426 /* Queue of currently owned NORMAL or PRIO_INHERIT type mutexes. */ 427 struct mutex_queue mutexq; 428 429 /* Queue of all owned PRIO_PROTECT mutexes. */ 430 struct mutex_queue pp_mutexq; 431 432 void *ret; 433 struct pthread_specific_elem *specific; 434 int specific_data_count; 435 436 /* Number rwlocks rdlocks held. */ 437 int rdlock_count; 438 439 /* 440 * Current locks bitmap for rtld. */ 441 int rtld_bits; 442 443 /* Thread control block */ 444 struct tcb *tcb; 445 446 /* Cleanup handlers Link List */ 447 struct pthread_cleanup *cleanup; 448 449 /* 450 * Magic value to help recognize a valid thread structure 451 * from an invalid one: 452 */ 453#define THR_MAGIC ((u_int32_t) 0xd09ba115) 454 u_int32_t magic; 455 456 /* Enable event reporting */ 457 int report_events; 458 459 /* Event mask */ 460 int event_mask; 461 462 /* Event */ 463 td_event_msg_t event_buf; 464}; 465 466#define THR_SHOULD_GC(thrd) \ 467 ((thrd)->refcount == 0 && (thrd)->state == PS_DEAD && \ 468 ((thrd)->flags & THR_FLAGS_DETACHED) != 0) 469 470#define THR_IN_CRITICAL(thrd) \ 471 (((thrd)->locklevel > 0) || \ 472 ((thrd)->critical_count > 0)) 473 474#define THR_CRITICAL_ENTER(thrd) \ 475 (thrd)->critical_count++ 476 477#define THR_CRITICAL_LEAVE(thrd) \ 478 do { \ 479 (thrd)->critical_count--; \ 480 _thr_ast(thrd); \ 481 } while (0) 482 483#define THR_UMUTEX_TRYLOCK(thrd, lck) \ 484 _thr_umutex_trylock((lck), TID(thrd)) 485 486#define THR_UMUTEX_LOCK(thrd, lck) \ 487 _thr_umutex_lock((lck), TID(thrd)) 488 489#define THR_UMUTEX_TIMEDLOCK(thrd, lck, timo) \ 490 _thr_umutex_timedlock((lck), TID(thrd), (timo)) 491 492#define THR_UMUTEX_UNLOCK(thrd, lck) \ 493 _thr_umutex_unlock((lck), TID(thrd)) 494 495#define THR_LOCK_ACQUIRE(thrd, lck) \ 496do { \ 497 (thrd)->locklevel++; \ 498 _thr_umutex_lock(lck, TID(thrd)); \ 499} while (0) 500 501#ifdef _PTHREADS_INVARIANTS 502#define THR_ASSERT_LOCKLEVEL(thrd) \ 503do { \ 504 if (__predict_false((thrd)->locklevel <= 0)) \ 505 _thr_assert_lock_level(); \ 506} while (0) 507#else 508#define THR_ASSERT_LOCKLEVEL(thrd) 509#endif 510 511#define THR_LOCK_RELEASE(thrd, lck) \ 512do { \ 513 THR_ASSERT_LOCKLEVEL(thrd); \ 514 _thr_umutex_unlock((lck), TID(thrd)); \ 515 (thrd)->locklevel--; \ 516 _thr_ast(thrd); \ 517} while (0) 518 519#define THR_LOCK(curthrd) THR_LOCK_ACQUIRE(curthrd, &(curthrd)->lock) 520#define THR_UNLOCK(curthrd) THR_LOCK_RELEASE(curthrd, &(curthrd)->lock) 521#define THR_THREAD_LOCK(curthrd, thr) THR_LOCK_ACQUIRE(curthrd, &(thr)->lock) 522#define THR_THREAD_UNLOCK(curthrd, thr) THR_LOCK_RELEASE(curthrd, &(thr)->lock) 523 524#define THREAD_LIST_RDLOCK(curthrd) \ 525do { \ 526 (curthrd)->locklevel++; \ 527 _thr_rwl_rdlock(&_thr_list_lock); \ 528} while (0) 529 530#define THREAD_LIST_WRLOCK(curthrd) \ 531do { \ 532 (curthrd)->locklevel++; \ 533 _thr_rwl_wrlock(&_thr_list_lock); \ 534} while (0) 535 536#define THREAD_LIST_UNLOCK(curthrd) \ 537do { \ 538 _thr_rwl_unlock(&_thr_list_lock); \ 539 (curthrd)->locklevel--; \ 540 _thr_ast(curthrd); \ 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)->flags & THR_FLAGS_IN_GCLIST) == 0) { \ 563 TAILQ_INSERT_HEAD(&_thread_gc_list, thrd, gcle);\ 564 (thrd)->flags |= THR_FLAGS_IN_GCLIST; \ 565 _gc_count++; \ 566 } \ 567} while (0) 568#define THR_GCLIST_REMOVE(thrd) do { \ 569 if (((thrd)->flags & THR_FLAGS_IN_GCLIST) != 0) { \ 570 TAILQ_REMOVE(&_thread_gc_list, thrd, gcle); \ 571 (thrd)->flags &= ~THR_FLAGS_IN_GCLIST; \ 572 _gc_count--; \ 573 } \ 574} while (0) 575 576#define THR_REF_ADD(curthread, pthread) { \ 577 THR_CRITICAL_ENTER(curthread); \ 578 pthread->refcount++; \ 579} while (0) 580 581#define THR_REF_DEL(curthread, pthread) { \ 582 pthread->refcount--; \ 583 THR_CRITICAL_LEAVE(curthread); \ 584} while (0) 585 586#define GC_NEEDED() (_gc_count >= 5) 587 588#define SHOULD_REPORT_EVENT(curthr, e) \ 589 (curthr->report_events && \ 590 (((curthr)->event_mask | _thread_event_mask ) & e) != 0) 591 592extern int __isthreaded; 593 594/* 595 * Global variables for the pthread kernel. 596 */ 597 598extern char *_usrstack __hidden; 599extern struct pthread *_thr_initial __hidden; 600 601/* For debugger */ 602extern int _libthr_debug; 603extern int _thread_event_mask; 604extern struct pthread *_thread_last_event; 605 606/* List of all threads: */ 607extern pthreadlist _thread_list; 608 609/* List of threads needing GC: */ 610extern pthreadlist _thread_gc_list __hidden; 611 612extern int _thread_active_threads; 613extern atfork_head _thr_atfork_list __hidden; 614extern struct urwlock _thr_atfork_lock __hidden; 615 616/* Default thread attributes: */ 617extern struct pthread_attr _pthread_attr_default __hidden; 618 619/* Default mutex attributes: */ 620extern struct pthread_mutex_attr _pthread_mutexattr_default __hidden; 621 622/* Default condition variable attributes: */ 623extern struct pthread_cond_attr _pthread_condattr_default __hidden; 624 625extern struct pthread_prio _thr_priorities[] __hidden; 626 627extern pid_t _thr_pid __hidden; 628extern int _thr_is_smp __hidden; 629 630extern size_t _thr_guard_default __hidden; 631extern size_t _thr_stack_default __hidden; 632extern size_t _thr_stack_initial __hidden; 633extern int _thr_page_size __hidden; 634extern int _thr_spinloops __hidden; 635extern int _thr_yieldloops __hidden; 636 637/* Garbage thread count. */ 638extern int _gc_count __hidden; 639 640extern struct umutex _mutex_static_lock __hidden; 641extern struct umutex _cond_static_lock __hidden; 642extern struct umutex _rwlock_static_lock __hidden; 643extern struct umutex _keytable_lock __hidden; 644extern struct urwlock _thr_list_lock __hidden; 645extern struct umutex _thr_event_lock __hidden; 646 647/* 648 * Function prototype definitions. 649 */ 650__BEGIN_DECLS 651int _thr_setthreaded(int) __hidden; 652int _mutex_cv_lock(pthread_mutex_t *, int count) __hidden; 653int _mutex_cv_unlock(pthread_mutex_t *, int *count) __hidden; 654int _mutex_reinit(pthread_mutex_t *) __hidden; 655void _mutex_fork(struct pthread *curthread) __hidden; 656void _libpthread_init(struct pthread *) __hidden; 657struct pthread *_thr_alloc(struct pthread *) __hidden; 658void _thread_exit(const char *, int, const char *) __hidden __dead2; 659int _thr_ref_add(struct pthread *, struct pthread *, int) __hidden; 660void _thr_ref_delete(struct pthread *, struct pthread *) __hidden; 661void _thr_ref_delete_unlocked(struct pthread *, struct pthread *) __hidden; 662int _thr_find_thread(struct pthread *, struct pthread *, int) __hidden; 663void _thr_rtld_init(void) __hidden; 664void _thr_rtld_fini(void) __hidden; 665void _thr_rtld_postfork_child(void) __hidden; 666int _thr_stack_alloc(struct pthread_attr *) __hidden; 667void _thr_stack_free(struct pthread_attr *) __hidden; 668void _thr_free(struct pthread *, struct pthread *) __hidden; 669void _thr_gc(struct pthread *) __hidden; 670void _thread_cleanupspecific(void) __hidden; 671void _thread_printf(int, const char *, ...) __hidden; 672void _thr_spinlock_init(void) __hidden; 673void _thr_cancel_enter(struct pthread *) __hidden; 674void _thr_cancel_enter2(struct pthread *, int) __hidden; 675void _thr_cancel_leave(struct pthread *, int) __hidden; 676void _thr_testcancel(struct pthread *) __hidden; 677void _thr_signal_block(struct pthread *) __hidden; 678void _thr_signal_unblock(struct pthread *) __hidden; 679void _thr_signal_init(void) __hidden; 680void _thr_signal_deinit(void) __hidden; 681int _thr_send_sig(struct pthread *, int sig) __hidden; 682void _thr_list_init(void) __hidden; 683void _thr_hash_add(struct pthread *) __hidden; 684void _thr_hash_remove(struct pthread *) __hidden; 685struct pthread *_thr_hash_find(struct pthread *) __hidden; 686void _thr_link(struct pthread *, struct pthread *) __hidden; 687void _thr_unlink(struct pthread *, struct pthread *) __hidden; 688void _thr_assert_lock_level(void) __hidden __dead2; 689void _thr_ast(struct pthread *) __hidden; 690void _thr_once_init(void) __hidden; 691void _thr_report_creation(struct pthread *curthread, 692 struct pthread *newthread) __hidden; 693void _thr_report_death(struct pthread *curthread) __hidden; 694int _thr_getscheduler(lwpid_t, int *, struct sched_param *) __hidden; 695int _thr_setscheduler(lwpid_t, int, const struct sched_param *) __hidden; 696void _thr_signal_prefork(void) __hidden; 697void _thr_signal_postfork(void) __hidden; 698void _thr_signal_postfork_child(void) __hidden; 699void _thr_try_gc(struct pthread *, struct pthread *) __hidden; 700int _rtp_to_schedparam(const struct rtprio *rtp, int *policy, 701 struct sched_param *param) __hidden; 702int _schedparam_to_rtp(int policy, const struct sched_param *param, 703 struct rtprio *rtp) __hidden; 704void _thread_bp_create(void); 705void _thread_bp_death(void); 706int _sched_yield(void); 707 708void _pthread_cleanup_push(void (*)(void *), void *); 709void _pthread_cleanup_pop(int); 710void _pthread_exit_mask(void *status, sigset_t *mask) __dead2 __hidden; 711 712 713/* #include <fcntl.h> */ 714#ifdef _SYS_FCNTL_H_ 715int __sys_fcntl(int, int, ...); 716int __sys_open(const char *, int, ...); 717int __sys_openat(int, const char *, int, ...); 718#endif 719 720/* #include <signal.h> */ 721#ifdef _SIGNAL_H_ 722int __sys_kill(pid_t, int); 723int __sys_sigaction(int, const struct sigaction *, struct sigaction *); 724int __sys_sigpending(sigset_t *); 725int __sys_sigprocmask(int, const sigset_t *, sigset_t *); 726int __sys_sigsuspend(const sigset_t *); 727int __sys_sigreturn(const ucontext_t *); 728int __sys_sigaltstack(const struct sigaltstack *, struct sigaltstack *); 729int __sys_sigwait(const sigset_t *, int *); 730int __sys_sigtimedwait(const sigset_t *, siginfo_t *, 731 const struct timespec *); 732int __sys_sigwaitinfo(const sigset_t *set, siginfo_t *info); 733#endif 734 735/* #include <time.h> */ 736#ifdef _TIME_H_ 737int __sys_nanosleep(const struct timespec *, struct timespec *); 738#endif 739 740/* #include <sys/ucontext.h> */ 741#ifdef _SYS_UCONTEXT_H_ 742int __sys_setcontext(const ucontext_t *ucp); 743int __sys_swapcontext(ucontext_t *oucp, const ucontext_t *ucp); 744#endif 745 746/* #include <unistd.h> */ 747#ifdef _UNISTD_H_ 748int __sys_close(int); 749int __sys_fork(void); 750pid_t __sys_getpid(void); 751ssize_t __sys_read(int, void *, size_t); 752ssize_t __sys_write(int, const void *, size_t); 753void __sys_exit(int); 754#endif 755 756int _umtx_op_err(void *, int op, u_long, void *, void *) __hidden; 757 758static inline int 759_thr_isthreaded(void) 760{ 761 return (__isthreaded != 0); 762} 763 764static inline int 765_thr_is_inited(void) 766{ 767 return (_thr_initial != NULL); 768} 769 770static inline void 771_thr_check_init(void) 772{ 773 if (_thr_initial == NULL) 774 _libpthread_init(NULL); 775} 776 777struct dl_phdr_info; 778void __pthread_cxa_finalize(struct dl_phdr_info *phdr_info); 779void _thr_tsd_unload(struct dl_phdr_info *phdr_info) __hidden; 780void _thr_sigact_unload(struct dl_phdr_info *phdr_info) __hidden; 781 782__END_DECLS 783 784#endif /* !_THR_PRIVATE_H */ 785