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