thr_private.h revision 155330
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 155330 2006-02-05 03:04:54Z 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 <sched.h> 49#include <unistd.h> 50#include <ucontext.h> 51#include <sys/thr.h> 52#include <pthread.h> 53 54#ifndef __hidden 55#define __hidden __attribute__((visibility("hidden"))) 56#endif 57 58#include "pthread_md.h" 59#include "thr_umtx.h" 60#include "thread_db.h" 61 62typedef TAILQ_HEAD(pthreadlist, pthread) pthreadlist; 63typedef TAILQ_HEAD(atfork_head, pthread_atfork) atfork_head; 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 112struct pthread_mutex { 113 /* 114 * Lock for accesses to this structure. 115 */ 116 volatile umtx_t m_lock; 117 enum pthread_mutextype m_type; 118 int m_protocol; 119 TAILQ_HEAD(mutex_head, pthread) m_queue; 120 struct pthread *m_owner; 121 long m_flags; 122 int m_count; 123 int m_refcount; 124 125 /* 126 * Used for priority inheritence and protection. 127 * 128 * m_prio - For priority inheritence, the highest active 129 * priority (threads locking the mutex inherit 130 * this priority). For priority protection, the 131 * ceiling priority of this mutex. 132 * m_saved_prio - mutex owners inherited priority before 133 * taking the mutex, restored when the owner 134 * unlocks the mutex. 135 */ 136 int m_prio; 137 int m_saved_prio; 138 139 /* 140 * Link for list of all mutexes a thread currently owns. 141 */ 142 TAILQ_ENTRY(pthread_mutex) m_qe; 143}; 144 145/* 146 * Flags for mutexes. 147 */ 148#define MUTEX_FLAGS_PRIVATE 0x01 149#define MUTEX_FLAGS_INITED 0x02 150#define MUTEX_FLAGS_BUSY 0x04 151 152struct pthread_mutex_attr { 153 enum pthread_mutextype m_type; 154 int m_protocol; 155 int m_ceiling; 156 long m_flags; 157}; 158 159#define PTHREAD_MUTEXATTR_STATIC_INITIALIZER \ 160 { PTHREAD_MUTEX_DEFAULT, PTHREAD_PRIO_NONE, 0, MUTEX_FLAGS_PRIVATE } 161 162struct pthread_cond { 163 /* 164 * Lock for accesses to this structure. 165 */ 166 volatile umtx_t c_lock; 167 volatile umtx_t c_seqno; 168 volatile int c_waiters; 169 volatile int c_wakeups; 170 int c_pshared; 171 int c_clockid; 172}; 173 174struct pthread_cond_attr { 175 int c_pshared; 176 int c_clockid; 177}; 178 179struct pthread_barrier { 180 volatile umtx_t b_lock; 181 volatile umtx_t b_cycle; 182 volatile int b_count; 183 volatile int b_waiters; 184}; 185 186struct pthread_barrierattr { 187 int pshared; 188}; 189 190struct pthread_spinlock { 191 volatile umtx_t s_lock; 192}; 193 194/* 195 * Flags for condition variables. 196 */ 197#define COND_FLAGS_PRIVATE 0x01 198#define COND_FLAGS_INITED 0x02 199#define COND_FLAGS_BUSY 0x04 200 201/* 202 * Cleanup definitions. 203 */ 204struct pthread_cleanup { 205 struct pthread_cleanup *next; 206 void (*routine)(); 207 void *routine_arg; 208 int onstack; 209}; 210 211#define THR_CLEANUP_PUSH(td, func, arg) { \ 212 struct pthread_cleanup __cup; \ 213 \ 214 __cup.routine = func; \ 215 __cup.routine_arg = arg; \ 216 __cup.onstack = 1; \ 217 __cup.next = (td)->cleanup; \ 218 (td)->cleanup = &__cup; 219 220#define THR_CLEANUP_POP(td, exec) \ 221 (td)->cleanup = __cup.next; \ 222 if ((exec) != 0) \ 223 __cup.routine(__cup.routine_arg); \ 224} 225 226struct pthread_atfork { 227 TAILQ_ENTRY(pthread_atfork) qe; 228 void (*prepare)(void); 229 void (*parent)(void); 230 void (*child)(void); 231}; 232 233struct pthread_attr { 234 int sched_policy; 235 int sched_inherit; 236 int sched_interval; 237 int prio; 238 int suspend; 239#define THR_STACK_USER 0x100 /* 0xFF reserved for <pthread.h> */ 240 int flags; 241 void *arg_attr; 242 void (*cleanup_attr)(); 243 void *stackaddr_attr; 244 size_t stacksize_attr; 245 size_t guardsize_attr; 246}; 247 248/* 249 * Thread creation state attributes. 250 */ 251#define THR_CREATE_RUNNING 0 252#define THR_CREATE_SUSPENDED 1 253 254/* 255 * Miscellaneous definitions. 256 */ 257#define THR_STACK_DEFAULT (sizeof(void *) / 4 * 1024 * 1024) 258 259/* 260 * Maximum size of initial thread's stack. This perhaps deserves to be larger 261 * than the stacks of other threads, since many applications are likely to run 262 * almost entirely on this stack. 263 */ 264#define THR_STACK_INITIAL (THR_STACK_DEFAULT * 2) 265 266/* 267 * Define the different priority ranges. All applications have thread 268 * priorities constrained within 0-31. The threads library raises the 269 * priority when delivering signals in order to ensure that signal 270 * delivery happens (from the POSIX spec) "as soon as possible". 271 * In the future, the threads library will also be able to map specific 272 * threads into real-time (cooperating) processes or kernel threads. 273 * The RT and SIGNAL priorities will be used internally and added to 274 * thread base priorities so that the scheduling queue can handle both 275 * normal and RT priority threads with and without signal handling. 276 * 277 * The approach taken is that, within each class, signal delivery 278 * always has priority over thread execution. 279 */ 280#define THR_DEFAULT_PRIORITY 15 281#define THR_MIN_PRIORITY 0 282#define THR_MAX_PRIORITY 31 /* 0x1F */ 283#define THR_SIGNAL_PRIORITY 32 /* 0x20 */ 284#define THR_RT_PRIORITY 64 /* 0x40 */ 285#define THR_FIRST_PRIORITY THR_MIN_PRIORITY 286#define THR_LAST_PRIORITY \ 287 (THR_MAX_PRIORITY + THR_SIGNAL_PRIORITY + THR_RT_PRIORITY) 288#define THR_BASE_PRIORITY(prio) ((prio) & THR_MAX_PRIORITY) 289 290/* 291 * Time slice period in microseconds. 292 */ 293#define TIMESLICE_USEC 20000 294 295struct pthread_rwlockattr { 296 int pshared; 297}; 298 299struct pthread_rwlock { 300 pthread_mutex_t lock; /* monitor lock */ 301 pthread_cond_t read_signal; 302 pthread_cond_t write_signal; 303 int state; /* 0 = idle >0 = # of readers -1 = writer */ 304 int blocked_writers; 305}; 306 307/* 308 * Thread states. 309 */ 310enum pthread_state { 311 PS_RUNNING, 312 PS_DEAD 313}; 314 315union pthread_wait_data { 316 pthread_mutex_t mutex; 317}; 318 319struct pthread_specific_elem { 320 const void *data; 321 int seqno; 322}; 323 324struct pthread_key { 325 volatile int allocated; 326 volatile int count; 327 int seqno; 328 void (*destructor)(void *); 329}; 330 331/* 332 * Thread structure. 333 */ 334struct pthread { 335 /* 336 * Magic value to help recognize a valid thread structure 337 * from an invalid one: 338 */ 339#define THR_MAGIC ((u_int32_t) 0xd09ba115) 340 u_int32_t magic; 341 342 /* 343 * Lock for accesses to this thread structure. 344 */ 345 umtx_t lock; 346 347 /* Kernel thread id. */ 348 long tid; 349#define TID_TERMINATED 1 350 351 /* Internal condition variable cycle number. */ 352 umtx_t cycle; 353 354 /* How many low level locks the thread held. */ 355 int locklevel; 356 357 /* 358 * Set to non-zero when this thread has entered a critical 359 * region. We allow for recursive entries into critical regions. 360 */ 361 int critical_count; 362 363 /* Signal blocked counter. */ 364 int sigblock; 365 366 /* Queue entry for list of all threads. */ 367 TAILQ_ENTRY(pthread) tle; /* link for all threads in process */ 368 369 /* Queue entry for GC lists. */ 370 TAILQ_ENTRY(pthread) gcle; 371 372 /* Hash queue entry. */ 373 LIST_ENTRY(pthread) hle; 374 375 /* Threads reference count. */ 376 int refcount; 377 378 /* 379 * Thread start routine, argument, stack pointer and thread 380 * attributes. 381 */ 382 void *(*start_routine)(void *); 383 void *arg; 384 struct pthread_attr attr; 385 386 /* 387 * Cancelability flags 388 */ 389#define THR_CANCEL_DISABLE 0x0001 390#define THR_CANCEL_EXITING 0x0002 391#define THR_CANCEL_AT_POINT 0x0004 392#define THR_CANCEL_NEEDED 0x0008 393#define SHOULD_CANCEL(val) \ 394 (((val) & (THR_CANCEL_DISABLE | THR_CANCEL_EXITING | \ 395 THR_CANCEL_NEEDED)) == THR_CANCEL_NEEDED) 396 397#define SHOULD_ASYNC_CANCEL(val) \ 398 (((val) & (THR_CANCEL_DISABLE | THR_CANCEL_EXITING | \ 399 THR_CANCEL_NEEDED | THR_CANCEL_AT_POINT)) == \ 400 (THR_CANCEL_NEEDED | THR_CANCEL_AT_POINT)) 401 int cancelflags; 402 403 /* Thread temporary signal mask. */ 404 sigset_t sigmask; 405 406 /* Thread state: */ 407 umtx_t state; 408 409 /* 410 * Error variable used instead of errno. The function __error() 411 * returns a pointer to this. 412 */ 413 int error; 414 415 /* 416 * The joiner is the thread that is joining to this thread. The 417 * join status keeps track of a join operation to another thread. 418 */ 419 struct pthread *joiner; 420 421 /* 422 * The current thread can belong to a priority mutex queue. 423 * This is the synchronization queue link. 424 */ 425 TAILQ_ENTRY(pthread) sqe; 426 427 /* Wait data. */ 428 union pthread_wait_data data; 429 430 int sflags; 431#define THR_FLAGS_IN_SYNCQ 0x0001 432 433 /* Miscellaneous flags; only set with scheduling lock held. */ 434 int flags; 435#define THR_FLAGS_PRIVATE 0x0001 436#define THR_FLAGS_NEED_SUSPEND 0x0002 /* thread should be suspended */ 437#define THR_FLAGS_SUSPENDED 0x0004 /* thread is suspended */ 438 439 /* Thread list flags; only set with thread list lock held. */ 440 int tlflags; 441#define TLFLAGS_GC_SAFE 0x0001 /* thread safe for cleaning */ 442#define TLFLAGS_IN_TDLIST 0x0002 /* thread in all thread list */ 443#define TLFLAGS_IN_GCLIST 0x0004 /* thread in gc list */ 444#define TLFLAGS_DETACHED 0x0008 /* thread is detached */ 445 446 /* 447 * Base priority is the user setable and retrievable priority 448 * of the thread. It is only affected by explicit calls to 449 * set thread priority and upon thread creation via a thread 450 * attribute or default priority. 451 */ 452 char base_priority; 453 454 /* 455 * Inherited priority is the priority a thread inherits by 456 * taking a priority inheritence or protection mutex. It 457 * is not affected by base priority changes. Inherited 458 * priority defaults to and remains 0 until a mutex is taken 459 * that is being waited on by any other thread whose priority 460 * is non-zero. 461 */ 462 char inherited_priority; 463 464 /* 465 * Active priority is always the maximum of the threads base 466 * priority and inherited priority. When there is a change 467 * in either the base or inherited priority, the active 468 * priority must be recalculated. 469 */ 470 char active_priority; 471 472 /* Number of priority ceiling or protection mutexes owned. */ 473 int priority_mutex_count; 474 475 /* Queue of currently owned simple type mutexes. */ 476 TAILQ_HEAD(, pthread_mutex) mutexq; 477 478 /* Queue of currently owned priority type mutexs. */ 479 TAILQ_HEAD(, pthread_mutex) pri_mutexq; 480 481 void *ret; 482 struct pthread_specific_elem *specific; 483 int specific_data_count; 484 485 /* Number rwlocks rdlocks held. */ 486 int rdlock_count; 487 488 /* 489 * Current locks bitmap for rtld. */ 490 int rtld_bits; 491 492 /* Thread control block */ 493 struct tcb *tcb; 494 495 /* Cleanup handlers Link List */ 496 struct pthread_cleanup *cleanup; 497 498 /* Enable event reporting */ 499 int report_events; 500 501 /* Event mask */ 502 int event_mask; 503 504 /* Event */ 505 td_event_msg_t event_buf; 506}; 507 508#define THR_IN_CRITICAL(thrd) \ 509 (((thrd)->locklevel > 0) || \ 510 ((thrd)->critical_count > 0)) 511 512#define THR_UMTX_TRYLOCK(thrd, lck) \ 513 _thr_umtx_trylock((lck), (thrd)->tid) 514 515#define THR_UMTX_LOCK(thrd, lck) \ 516 _thr_umtx_lock((lck), (thrd)->tid) 517 518#define THR_UMTX_TIMEDLOCK(thrd, lck, timo) \ 519 _thr_umtx_timedlock((lck), (thrd)->tid, (timo)) 520 521#define THR_UMTX_UNLOCK(thrd, lck) \ 522 _thr_umtx_unlock((lck), (thrd)->tid) 523 524#define THR_LOCK_ACQUIRE(thrd, lck) \ 525do { \ 526 (thrd)->locklevel++; \ 527 _thr_umtx_lock(lck, (thrd)->tid); \ 528} while (0) 529 530#ifdef _PTHREADS_INVARIANTS 531#define THR_ASSERT_LOCKLEVEL(thrd) \ 532do { \ 533 if (__predict_false((thrd)->locklevel <= 0)) \ 534 _thr_assert_lock_level(); \ 535} while (0) 536#else 537#define THR_ASSERT_LOCKLEVEL(thrd) 538#endif 539 540#define THR_LOCK_RELEASE(thrd, lck) \ 541do { \ 542 THR_ASSERT_LOCKLEVEL(thrd); \ 543 _thr_umtx_unlock((lck), (thrd)->tid); \ 544 (thrd)->locklevel--; \ 545 _thr_ast(thrd); \ 546} while (0) 547 548#define THR_LOCK(curthrd) THR_LOCK_ACQUIRE(curthrd, &(curthrd)->lock) 549#define THR_UNLOCK(curthrd) THR_LOCK_RELEASE(curthrd, &(curthrd)->lock) 550#define THR_THREAD_LOCK(curthrd, thr) THR_LOCK_ACQUIRE(curthrd, &(thr)->lock) 551#define THR_THREAD_UNLOCK(curthrd, thr) THR_LOCK_RELEASE(curthrd, &(thr)->lock) 552 553#define THREAD_LIST_LOCK(curthrd) \ 554do { \ 555 THR_LOCK_ACQUIRE((curthrd), &_thr_list_lock); \ 556} while (0) 557 558#define THREAD_LIST_UNLOCK(curthrd) \ 559do { \ 560 THR_LOCK_RELEASE((curthrd), &_thr_list_lock); \ 561} while (0) 562 563/* 564 * Macros to insert/remove threads to the all thread list and 565 * the gc list. 566 */ 567#define THR_LIST_ADD(thrd) do { \ 568 if (((thrd)->tlflags & TLFLAGS_IN_TDLIST) == 0) { \ 569 TAILQ_INSERT_HEAD(&_thread_list, thrd, tle); \ 570 _thr_hash_add(thrd); \ 571 (thrd)->tlflags |= TLFLAGS_IN_TDLIST; \ 572 } \ 573} while (0) 574#define THR_LIST_REMOVE(thrd) do { \ 575 if (((thrd)->tlflags & TLFLAGS_IN_TDLIST) != 0) { \ 576 TAILQ_REMOVE(&_thread_list, thrd, tle); \ 577 _thr_hash_remove(thrd); \ 578 (thrd)->tlflags &= ~TLFLAGS_IN_TDLIST; \ 579 } \ 580} while (0) 581#define THR_GCLIST_ADD(thrd) do { \ 582 if (((thrd)->tlflags & TLFLAGS_IN_GCLIST) == 0) { \ 583 TAILQ_INSERT_HEAD(&_thread_gc_list, thrd, gcle);\ 584 (thrd)->tlflags |= TLFLAGS_IN_GCLIST; \ 585 _gc_count++; \ 586 } \ 587} while (0) 588#define THR_GCLIST_REMOVE(thrd) do { \ 589 if (((thrd)->tlflags & TLFLAGS_IN_GCLIST) != 0) { \ 590 TAILQ_REMOVE(&_thread_gc_list, thrd, gcle); \ 591 (thrd)->tlflags &= ~TLFLAGS_IN_GCLIST; \ 592 _gc_count--; \ 593 } \ 594} while (0) 595 596#define GC_NEEDED() (_gc_count >= 5) 597 598#define THR_IN_SYNCQ(thrd) (((thrd)->sflags & THR_FLAGS_IN_SYNCQ) != 0) 599 600#define SHOULD_REPORT_EVENT(curthr, e) \ 601 (curthr->report_events && \ 602 (((curthr)->event_mask | _thread_event_mask ) & e) != 0) 603 604extern int __isthreaded; 605 606/* 607 * Global variables for the pthread kernel. 608 */ 609 610extern void *_usrstack __hidden; 611extern struct pthread *_thr_initial __hidden; 612extern int _thr_scope_system __hidden; 613 614/* For debugger */ 615extern int _libthr_debug; 616extern int _thread_event_mask; 617extern struct pthread *_thread_last_event; 618 619/* List of all threads: */ 620extern pthreadlist _thread_list; 621 622/* List of threads needing GC: */ 623extern pthreadlist _thread_gc_list __hidden; 624 625extern int _thread_active_threads; 626extern atfork_head _thr_atfork_list __hidden; 627extern umtx_t _thr_atfork_lock __hidden; 628 629/* Default thread attributes: */ 630extern struct pthread_attr _pthread_attr_default __hidden; 631 632/* Default mutex attributes: */ 633extern struct pthread_mutex_attr _pthread_mutexattr_default __hidden; 634 635/* Default condition variable attributes: */ 636extern struct pthread_cond_attr _pthread_condattr_default __hidden; 637 638extern pid_t _thr_pid __hidden; 639extern int _thr_guard_default __hidden; 640extern int _thr_stack_default __hidden; 641extern int _thr_stack_initial __hidden; 642extern int _thr_page_size __hidden; 643/* Garbage thread count. */ 644extern int _gc_count __hidden; 645 646extern umtx_t _mutex_static_lock __hidden; 647extern umtx_t _cond_static_lock __hidden; 648extern umtx_t _rwlock_static_lock __hidden; 649extern umtx_t _keytable_lock __hidden; 650extern umtx_t _thr_list_lock __hidden; 651extern umtx_t _thr_event_lock __hidden; 652 653/* 654 * Function prototype definitions. 655 */ 656__BEGIN_DECLS 657int _thr_setthreaded(int) __hidden; 658int _mutex_cv_lock(pthread_mutex_t *) __hidden; 659int _mutex_cv_unlock(pthread_mutex_t *) __hidden; 660void _mutex_notify_priochange(struct pthread *, struct pthread *, int) __hidden; 661int _mutex_reinit(pthread_mutex_t *) __hidden; 662void _mutex_fork(struct pthread *curthread) __hidden; 663void _mutex_unlock_private(struct pthread *) __hidden; 664void _libpthread_init(struct pthread *) __hidden; 665void *_pthread_getspecific(pthread_key_t); 666int _pthread_cond_init(pthread_cond_t *, const pthread_condattr_t *); 667int _pthread_cond_destroy(pthread_cond_t *); 668int _pthread_cond_wait(pthread_cond_t *, pthread_mutex_t *); 669int _pthread_cond_timedwait(pthread_cond_t *, pthread_mutex_t *, 670 const struct timespec *); 671int _pthread_cond_signal(pthread_cond_t *); 672int _pthread_cond_broadcast(pthread_cond_t *); 673int _pthread_create(pthread_t * thread, const pthread_attr_t * attr, 674 void *(*start_routine) (void *), void *arg); 675int _pthread_key_create(pthread_key_t *, void (*) (void *)); 676int _pthread_key_delete(pthread_key_t); 677int _pthread_mutex_destroy(pthread_mutex_t *); 678int _pthread_mutex_init(pthread_mutex_t *, const pthread_mutexattr_t *); 679int _pthread_mutex_lock(pthread_mutex_t *); 680int _pthread_mutex_trylock(pthread_mutex_t *); 681int _pthread_mutex_unlock(pthread_mutex_t *); 682int _pthread_mutexattr_init(pthread_mutexattr_t *); 683int _pthread_mutexattr_destroy(pthread_mutexattr_t *); 684int _pthread_mutexattr_settype(pthread_mutexattr_t *, int); 685int _pthread_once(pthread_once_t *, void (*) (void)); 686int _pthread_rwlock_init(pthread_rwlock_t *, const pthread_rwlockattr_t *); 687int _pthread_rwlock_destroy (pthread_rwlock_t *); 688struct pthread *_pthread_self(void); 689int _pthread_setspecific(pthread_key_t, const void *); 690void _pthread_testcancel(void); 691void _pthread_yield(void); 692void _pthread_cleanup_push(void (*routine) (void *), void *routine_arg); 693void _pthread_cleanup_pop(int execute); 694struct pthread *_thr_alloc(struct pthread *) __hidden; 695void _thread_exit(char *, int, char *) __hidden __dead2; 696void _thr_exit_cleanup(void) __hidden; 697int _thr_ref_add(struct pthread *, struct pthread *, int) __hidden; 698void _thr_ref_delete(struct pthread *, struct pthread *) __hidden; 699void _thr_ref_delete_unlocked(struct pthread *, struct pthread *) __hidden; 700int _thr_find_thread(struct pthread *, struct pthread *, int) __hidden; 701void _thr_rtld_init(void) __hidden; 702void _thr_rtld_fini(void) __hidden; 703int _thr_stack_alloc(struct pthread_attr *) __hidden; 704void _thr_stack_free(struct pthread_attr *) __hidden; 705void _thr_free(struct pthread *, struct pthread *) __hidden; 706void _thr_gc(struct pthread *) __hidden; 707void _thread_cleanupspecific(void) __hidden; 708void _thread_dump_info(void) __hidden; 709void _thread_printf(int, const char *, ...) __hidden; 710void _thr_spinlock_init(void) __hidden; 711int _thr_cancel_enter(struct pthread *) __hidden; 712void _thr_cancel_leave(struct pthread *, int) __hidden; 713void _thr_signal_block(struct pthread *) __hidden; 714void _thr_signal_unblock(struct pthread *) __hidden; 715void _thr_signal_init(void) __hidden; 716void _thr_signal_deinit(void) __hidden; 717int _thr_send_sig(struct pthread *, int sig) __hidden; 718void _thr_list_init(void) __hidden; 719void _thr_hash_add(struct pthread *) __hidden; 720void _thr_hash_remove(struct pthread *) __hidden; 721struct pthread *_thr_hash_find(struct pthread *) __hidden; 722void _thr_link(struct pthread *, struct pthread *) __hidden; 723void _thr_unlink(struct pthread *, struct pthread *) __hidden; 724void _thr_suspend_check(struct pthread *) __hidden; 725void _thr_assert_lock_level(void) __hidden __dead2; 726void _thr_ast(struct pthread *) __hidden; 727void _thr_timer_init(void) __hidden; 728void _thr_report_creation(struct pthread *curthread, 729 struct pthread *newthread) __hidden; 730void _thr_report_death(struct pthread *curthread) __hidden; 731void _thread_bp_create(void); 732void _thread_bp_death(void); 733 734/* #include <sys/aio.h> */ 735#ifdef _SYS_AIO_H_ 736int __sys_aio_suspend(const struct aiocb * const[], int, const struct timespec *); 737#endif 738 739/* #include <fcntl.h> */ 740#ifdef _SYS_FCNTL_H_ 741int __sys_fcntl(int, int, ...); 742int __sys_open(const char *, int, ...); 743#endif 744 745/* #include <sys/ioctl.h> */ 746#ifdef _SYS_IOCTL_H_ 747int __sys_ioctl(int, unsigned long, ...); 748#endif 749 750/* #inclde <sched.h> */ 751#ifdef _SCHED_H_ 752int __sys_sched_yield(void); 753#endif 754 755/* #include <signal.h> */ 756#ifdef _SIGNAL_H_ 757int __sys_kill(pid_t, int); 758int __sys_sigaction(int, const struct sigaction *, struct sigaction *); 759int __sys_sigpending(sigset_t *); 760int __sys_sigprocmask(int, const sigset_t *, sigset_t *); 761int __sys_sigsuspend(const sigset_t *); 762int __sys_sigreturn(ucontext_t *); 763int __sys_sigaltstack(const struct sigaltstack *, struct sigaltstack *); 764#endif 765 766/* #include <sys/socket.h> */ 767#ifdef _SYS_SOCKET_H_ 768int __sys_accept(int, struct sockaddr *, socklen_t *); 769int __sys_connect(int, const struct sockaddr *, socklen_t); 770ssize_t __sys_recv(int, void *, size_t, int); 771ssize_t __sys_recvfrom(int, void *, size_t, int, struct sockaddr *, socklen_t *); 772ssize_t __sys_recvmsg(int, struct msghdr *, int); 773int __sys_sendfile(int, int, off_t, size_t, struct sf_hdtr *, 774 off_t *, int); 775ssize_t __sys_sendmsg(int, const struct msghdr *, int); 776ssize_t __sys_sendto(int, const void *,size_t, int, const struct sockaddr *, socklen_t); 777#endif 778 779/* #include <sys/uio.h> */ 780#ifdef _SYS_UIO_H_ 781ssize_t __sys_readv(int, const struct iovec *, int); 782ssize_t __sys_writev(int, const struct iovec *, int); 783#endif 784 785/* #include <time.h> */ 786#ifdef _TIME_H_ 787int __sys_nanosleep(const struct timespec *, struct timespec *); 788#endif 789 790/* #include <unistd.h> */ 791#ifdef _UNISTD_H_ 792int __sys_close(int); 793int __sys_execve(const char *, char * const *, char * const *); 794int __sys_fork(void); 795int __sys_fsync(int); 796pid_t __sys_getpid(void); 797int __sys_select(int, fd_set *, fd_set *, fd_set *, struct timeval *); 798ssize_t __sys_read(int, void *, size_t); 799ssize_t __sys_write(int, const void *, size_t); 800void __sys_exit(int); 801int __sys_sigwait(const sigset_t *, int *); 802int __sys_sigtimedwait(const sigset_t *, siginfo_t *, 803 const struct timespec *); 804int __sys_sigwaitinfo(const sigset_t *set, siginfo_t *info); 805#endif 806 807/* #include <poll.h> */ 808#ifdef _SYS_POLL_H_ 809int __sys_poll(struct pollfd *, unsigned, int); 810#endif 811 812/* #include <sys/mman.h> */ 813#ifdef _SYS_MMAN_H_ 814int __sys_msync(void *, size_t, int); 815#endif 816 817static inline int 818_thr_isthreaded(void) 819{ 820 return (__isthreaded != 0); 821} 822 823static inline int 824_thr_is_inited(void) 825{ 826 return (_thr_initial != NULL); 827} 828 829static inline void 830_thr_check_init(void) 831{ 832 if (_thr_initial == NULL) 833 _libpthread_init(NULL); 834} 835 836__END_DECLS 837 838#endif /* !_THR_PRIVATE_H */ 839