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