2 * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
32 * Private thread definitions for the uthread kernel.
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.9 2006/03/19 13:07:12 davidxu Exp $
38 #ifndef _THR_PRIVATE_H
39 #define _THR_PRIVATE_H
44 #include <sys/types.h>
46 #include <sys/cdefs.h>
47 #include <sys/queue.h>
48 #include <machine/atomic.h>
56 #include <pthread_np.h>
58 #include "pthread_md.h"
60 #include "thread_db.h"
63 * Evaluate the storage class specifier.
65 #ifdef GLOBAL_PTHREAD_PRIVATE
67 #define SCLASS_PRESET(x...) = x
70 #define SCLASS_PRESET(x...)
73 /* Signal to do cancellation */
77 * Kernel fatal error handler macro.
79 #define PANIC(string) _thread_exit(__FILE__,__LINE__,string)
81 /* Output debug messages like this: */
82 #define stdout_debug(args...) _thread_printf(STDOUT_FILENO, ##args)
83 #define stderr_debug(args...) _thread_printf(STDOUT_FILENO, ##args)
86 #define __predict_true(exp) (exp)
87 #define __predict_false(exp) (exp)
90 #ifdef _PTHREADS_INVARIANTS
91 #define THR_ASSERT(cond, msg) do { \
92 if (__predict_false(!(cond))) \
96 #define THR_ASSERT(cond, msg)
99 #define TIMESPEC_ADD(dst, src, val) \
101 (dst)->tv_sec = (src)->tv_sec + (val)->tv_sec; \
102 (dst)->tv_nsec = (src)->tv_nsec + (val)->tv_nsec; \
103 if ((dst)->tv_nsec >= 1000000000) { \
105 (dst)->tv_nsec -= 1000000000; \
109 #define TIMESPEC_SUB(dst, src, val) \
111 (dst)->tv_sec = (src)->tv_sec - (val)->tv_sec; \
112 (dst)->tv_nsec = (src)->tv_nsec - (val)->tv_nsec; \
113 if ((dst)->tv_nsec < 0) { \
115 (dst)->tv_nsec += 1000000000; \
119 struct pthread_mutex {
121 * Lock for accesses to this structure.
123 volatile umtx_t m_lock;
124 enum pthread_mutextype m_type;
126 TAILQ_HEAD(mutex_head, pthread) m_queue;
127 struct pthread *m_owner;
133 * Used for priority inheritence and protection.
135 * m_prio - For priority inheritence, the highest active
136 * priority (threads locking the mutex inherit
137 * this priority). For priority protection, the
138 * ceiling priority of this mutex.
139 * m_saved_prio - mutex owners inherited priority before
140 * taking the mutex, restored when the owner
147 * Link for list of all mutexes a thread currently owns.
149 TAILQ_ENTRY(pthread_mutex) m_qe;
152 #define TAILQ_INITIALIZER { NULL, NULL }
154 #define PTHREAD_MUTEX_STATIC_INITIALIZER \
155 {0, PTHREAD_MUTEX_DEFAULT, PTHREAD_PRIO_NONE, TAILQ_INITIALIZER, \
156 NULL, { NULL }, MUTEX_FLAGS_PRIVATE, 0, 0, 0, TAILQ_INITIALIZER }
160 #define MUTEX_FLAGS_PRIVATE 0x01
161 #define MUTEX_FLAGS_INITED 0x02
162 #define MUTEX_FLAGS_BUSY 0x04
164 struct pthread_mutex_attr {
165 enum pthread_mutextype m_type;
171 #define PTHREAD_MUTEXATTR_STATIC_INITIALIZER \
172 { PTHREAD_MUTEX_DEFAULT, PTHREAD_PRIO_NONE, 0, MUTEX_FLAGS_PRIVATE }
174 struct pthread_cond {
176 * Lock for accesses to this structure.
178 volatile umtx_t c_lock;
179 volatile umtx_t c_seqno;
180 volatile int c_waiters;
181 volatile int c_wakeups;
186 struct pthread_cond_attr {
191 struct pthread_barrier {
192 volatile umtx_t b_lock;
193 volatile umtx_t b_cycle;
194 volatile int b_count;
195 volatile int b_waiters;
198 struct pthread_barrierattr {
202 struct pthread_spinlock {
203 volatile umtx_t s_lock;
207 * Flags for condition variables.
209 #define COND_FLAGS_PRIVATE 0x01
210 #define COND_FLAGS_INITED 0x02
211 #define COND_FLAGS_BUSY 0x04
214 * Cleanup definitions.
216 struct pthread_cleanup {
217 struct pthread_cleanup *next;
223 #define THR_CLEANUP_PUSH(td, func, arg) { \
224 struct pthread_cleanup __cup; \
226 __cup.routine = func; \
227 __cup.routine_arg = arg; \
229 __cup.next = (td)->cleanup; \
230 (td)->cleanup = &__cup;
232 #define THR_CLEANUP_POP(td, exec) \
233 (td)->cleanup = __cup.next; \
235 __cup.routine(__cup.routine_arg); \
238 struct pthread_atfork {
239 TAILQ_ENTRY(pthread_atfork) qe;
240 void (*prepare)(void);
241 void (*parent)(void);
245 struct pthread_attr {
251 #define THR_STACK_USER 0x100 /* 0xFF reserved for <pthread.h> */
254 void (*cleanup_attr)();
255 void *stackaddr_attr;
256 size_t stacksize_attr;
257 size_t guardsize_attr;
261 * Thread creation state attributes.
263 #define THR_CREATE_RUNNING 0
264 #define THR_CREATE_SUSPENDED 1
267 * Miscellaneous definitions.
269 #define THR_STACK_DEFAULT (sizeof(void *) / 4 * 1024 * 1024)
272 * Maximum size of initial thread's stack. This perhaps deserves to be larger
273 * than the stacks of other threads, since many applications are likely to run
274 * almost entirely on this stack.
276 #define THR_STACK_INITIAL (THR_STACK_DEFAULT * 2)
279 * Define the different priority ranges. All applications have thread
280 * priorities constrained within 0-31. The threads library raises the
281 * priority when delivering signals in order to ensure that signal
282 * delivery happens (from the POSIX spec) "as soon as possible".
283 * In the future, the threads library will also be able to map specific
284 * threads into real-time (cooperating) processes or kernel threads.
285 * The RT and SIGNAL priorities will be used internally and added to
286 * thread base priorities so that the scheduling queue can handle both
287 * normal and RT priority threads with and without signal handling.
289 * The approach taken is that, within each class, signal delivery
290 * always has priority over thread execution.
292 #define THR_DEFAULT_PRIORITY 15
293 #define THR_MIN_PRIORITY 0
294 #define THR_MAX_PRIORITY 31 /* 0x1F */
295 #define THR_SIGNAL_PRIORITY 32 /* 0x20 */
296 #define THR_RT_PRIORITY 64 /* 0x40 */
297 #define THR_FIRST_PRIORITY THR_MIN_PRIORITY
298 #define THR_LAST_PRIORITY \
299 (THR_MAX_PRIORITY + THR_SIGNAL_PRIORITY + THR_RT_PRIORITY)
300 #define THR_BASE_PRIORITY(prio) ((prio) & THR_MAX_PRIORITY)
303 * Time slice period in microseconds.
305 #define TIMESLICE_USEC 20000
307 struct pthread_rwlockattr {
311 struct pthread_rwlock {
312 pthread_mutex_t lock; /* monitor lock */
313 pthread_cond_t read_signal;
314 pthread_cond_t write_signal;
315 int state; /* 0 = idle >0 = # of readers -1 = writer */
327 union pthread_wait_data {
328 pthread_mutex_t mutex;
331 struct pthread_specific_elem {
337 volatile int allocated;
340 void (*destructor)(void *);
348 * Magic value to help recognize a valid thread structure
349 * from an invalid one:
351 #define THR_MAGIC ((u_int32_t) 0xd09ba115)
354 u_int64_t uniqueid; /* for gdb */
357 * Lock for accesses to this thread structure.
361 /* Thread is terminated in kernel, written by kernel. */
364 /* Kernel thread id. */
367 /* Internal condition variable cycle number. */
370 /* How many low level locks the thread held. */
374 * Set to non-zero when this thread has entered a critical
375 * region. We allow for recursive entries into critical regions.
379 /* Signal blocked counter. */
382 /* Queue entry for list of all threads. */
383 TAILQ_ENTRY(pthread) tle; /* link for all threads in process */
385 /* Queue entry for GC lists. */
386 TAILQ_ENTRY(pthread) gcle;
388 /* Hash queue entry. */
389 LIST_ENTRY(pthread) hle;
391 /* Threads reference count. */
395 * Thread start routine, argument, stack pointer and thread
398 void *(*start_routine)(void *);
400 struct pthread_attr attr;
403 * Cancelability flags
405 #define THR_CANCEL_DISABLE 0x0001
406 #define THR_CANCEL_EXITING 0x0002
407 #define THR_CANCEL_AT_POINT 0x0004
408 #define THR_CANCEL_NEEDED 0x0008
409 #define SHOULD_CANCEL(val) \
410 (((val) & (THR_CANCEL_DISABLE | THR_CANCEL_EXITING | \
411 THR_CANCEL_NEEDED)) == THR_CANCEL_NEEDED)
413 #define SHOULD_ASYNC_CANCEL(val) \
414 (((val) & (THR_CANCEL_DISABLE | THR_CANCEL_EXITING | \
415 THR_CANCEL_NEEDED | THR_CANCEL_AT_POINT)) == \
416 (THR_CANCEL_NEEDED | THR_CANCEL_AT_POINT))
419 /* Thread temporary signal mask. */
426 * Error variable used instead of errno, used for internal.
431 * The joiner is the thread that is joining to this thread. The
432 * join status keeps track of a join operation to another thread.
434 struct pthread *joiner;
437 * The current thread can belong to a priority mutex queue.
438 * This is the synchronization queue link.
440 TAILQ_ENTRY(pthread) sqe;
443 union pthread_wait_data data;
446 #define THR_FLAGS_IN_SYNCQ 0x0001
448 /* Miscellaneous flags; only set with scheduling lock held. */
450 #define THR_FLAGS_PRIVATE 0x0001
451 #define THR_FLAGS_NEED_SUSPEND 0x0002 /* thread should be suspended */
452 #define THR_FLAGS_SUSPENDED 0x0004 /* thread is suspended */
454 /* Thread list flags; only set with thread list lock held. */
456 #define TLFLAGS_GC_SAFE 0x0001 /* thread safe for cleaning */
457 #define TLFLAGS_IN_TDLIST 0x0002 /* thread in all thread list */
458 #define TLFLAGS_IN_GCLIST 0x0004 /* thread in gc list */
459 #define TLFLAGS_DETACHED 0x0008 /* thread is detached */
462 * Base priority is the user setable and retrievable priority
463 * of the thread. It is only affected by explicit calls to
464 * set thread priority and upon thread creation via a thread
465 * attribute or default priority.
470 * Inherited priority is the priority a thread inherits by
471 * taking a priority inheritence or protection mutex. It
472 * is not affected by base priority changes. Inherited
473 * priority defaults to and remains 0 until a mutex is taken
474 * that is being waited on by any other thread whose priority
477 char inherited_priority;
480 * Active priority is always the maximum of the threads base
481 * priority and inherited priority. When there is a change
482 * in either the base or inherited priority, the active
483 * priority must be recalculated.
485 char active_priority;
487 /* Number of priority ceiling or protection mutexes owned. */
488 int priority_mutex_count;
490 /* Queue of currently owned simple type mutexes. */
491 TAILQ_HEAD(, pthread_mutex) mutexq;
493 /* Queue of currently owned priority type mutexs. */
494 TAILQ_HEAD(, pthread_mutex) pri_mutexq;
497 struct pthread_specific_elem *specific;
498 int specific_data_count;
500 /* Number rwlocks rdlocks held. */
504 * Current locks bitmap for rtld. */
507 /* Thread control block */
510 /* Cleanup handlers Link List */
511 struct pthread_cleanup *cleanup;
513 /* Enable event reporting */
517 td_thr_events_t event_mask;
520 td_event_msg_t event_buf;
523 #define THR_IN_CRITICAL(thrd) \
524 (((thrd)->locklevel > 0) || \
525 ((thrd)->critical_count > 0))
527 #define THR_UMTX_TRYLOCK(thrd, lck) \
528 _thr_umtx_trylock((lck), (thrd)->tid)
530 #define THR_UMTX_LOCK(thrd, lck) \
531 _thr_umtx_lock((lck), (thrd)->tid)
533 #define THR_UMTX_TIMEDLOCK(thrd, lck, timo) \
534 _thr_umtx_timedlock((lck), (thrd)->tid, (timo))
536 #define THR_UMTX_UNLOCK(thrd, lck) \
537 _thr_umtx_unlock((lck), (thrd)->tid)
539 #define THR_LOCK_ACQUIRE(thrd, lck) \
541 (thrd)->locklevel++; \
542 _thr_umtx_lock(lck, (thrd)->tid); \
545 #ifdef _PTHREADS_INVARIANTS
546 #define THR_ASSERT_LOCKLEVEL(thrd) \
548 if (__predict_false((thrd)->locklevel <= 0)) \
549 _thr_assert_lock_level(); \
552 #define THR_ASSERT_LOCKLEVEL(thrd)
555 #define THR_LOCK_RELEASE(thrd, lck) \
557 THR_ASSERT_LOCKLEVEL(thrd); \
558 _thr_umtx_unlock((lck), (thrd)->tid); \
559 (thrd)->locklevel--; \
563 #define THR_LOCK(curthrd) THR_LOCK_ACQUIRE(curthrd, &(curthrd)->lock)
564 #define THR_UNLOCK(curthrd) THR_LOCK_RELEASE(curthrd, &(curthrd)->lock)
565 #define THR_THREAD_LOCK(curthrd, thr) THR_LOCK_ACQUIRE(curthrd, &(thr)->lock)
566 #define THR_THREAD_UNLOCK(curthrd, thr) THR_LOCK_RELEASE(curthrd, &(thr)->lock)
568 #define THREAD_LIST_LOCK(curthrd) \
570 THR_LOCK_ACQUIRE((curthrd), &_thr_list_lock); \
573 #define THREAD_LIST_UNLOCK(curthrd) \
575 THR_LOCK_RELEASE((curthrd), &_thr_list_lock); \
579 * Macros to insert/remove threads to the all thread list and
582 #define THR_LIST_ADD(thrd) do { \
583 if (((thrd)->tlflags & TLFLAGS_IN_TDLIST) == 0) { \
584 TAILQ_INSERT_HEAD(&_thread_list, thrd, tle); \
585 _thr_hash_add(thrd); \
586 (thrd)->tlflags |= TLFLAGS_IN_TDLIST; \
589 #define THR_LIST_REMOVE(thrd) do { \
590 if (((thrd)->tlflags & TLFLAGS_IN_TDLIST) != 0) { \
591 TAILQ_REMOVE(&_thread_list, thrd, tle); \
592 _thr_hash_remove(thrd); \
593 (thrd)->tlflags &= ~TLFLAGS_IN_TDLIST; \
596 #define THR_GCLIST_ADD(thrd) do { \
597 if (((thrd)->tlflags & TLFLAGS_IN_GCLIST) == 0) { \
598 TAILQ_INSERT_HEAD(&_thread_gc_list, thrd, gcle);\
599 (thrd)->tlflags |= TLFLAGS_IN_GCLIST; \
603 #define THR_GCLIST_REMOVE(thrd) do { \
604 if (((thrd)->tlflags & TLFLAGS_IN_GCLIST) != 0) { \
605 TAILQ_REMOVE(&_thread_gc_list, thrd, gcle); \
606 (thrd)->tlflags &= ~TLFLAGS_IN_GCLIST; \
611 #define GC_NEEDED() (_gc_count >= 5)
613 #define THR_IN_SYNCQ(thrd) (((thrd)->sflags & THR_FLAGS_IN_SYNCQ) != 0)
615 #define SHOULD_REPORT_EVENT(curthr, e) \
616 (curthr->report_events && \
617 (((curthr)->event_mask | _thread_event_mask ) & e) != 0)
619 extern int __isthreaded;
622 * Global variables for the pthread kernel.
625 SCLASS void *_usrstack SCLASS_PRESET(NULL);
626 SCLASS struct pthread *_thr_initial SCLASS_PRESET(NULL);
627 SCLASS int _thread_scope_system SCLASS_PRESET(0);
630 SCLASS int _libthread_xu_debug SCLASS_PRESET(0);
631 SCLASS int _thread_event_mask SCLASS_PRESET(0);
632 SCLASS struct pthread *_thread_last_event;
634 /* List of all threads: */
635 SCLASS TAILQ_HEAD(, pthread) _thread_list
636 SCLASS_PRESET(TAILQ_HEAD_INITIALIZER(_thread_list));
638 /* List of threads needing GC: */
639 SCLASS TAILQ_HEAD(, pthread) _thread_gc_list
640 SCLASS_PRESET(TAILQ_HEAD_INITIALIZER(_thread_gc_list));
642 SCLASS int _thread_active_threads SCLASS_PRESET(1);
644 SCLASS TAILQ_HEAD(atfork_head, pthread_atfork) _thr_atfork_list;
645 SCLASS umtx_t _thr_atfork_lock;
647 /* Default thread attributes: */
648 SCLASS struct pthread_attr _pthread_attr_default
650 .sched_policy = SCHED_RR,
652 .sched_interval = TIMESLICE_USEC,
653 .prio = THR_DEFAULT_PRIORITY,
654 .suspend = THR_CREATE_RUNNING,
657 .cleanup_attr = NULL,
658 .stackaddr_attr = NULL,
659 .stacksize_attr = THR_STACK_DEFAULT,
663 /* Default mutex attributes: */
664 SCLASS struct pthread_mutex_attr _pthread_mutexattr_default
666 .m_type = PTHREAD_MUTEX_DEFAULT,
667 .m_protocol = PTHREAD_PRIO_NONE,
672 /* Default condition variable attributes: */
673 SCLASS struct pthread_cond_attr _pthread_condattr_default
675 .c_pshared = PTHREAD_PROCESS_PRIVATE,
676 .c_clockid = CLOCK_REALTIME
679 SCLASS pid_t _thr_pid SCLASS_PRESET(0);
680 SCLASS int _thr_guard_default;
681 SCLASS int _thr_stack_default SCLASS_PRESET(THR_STACK_DEFAULT);
682 SCLASS int _thr_stack_initial SCLASS_PRESET(THR_STACK_INITIAL);
683 SCLASS int _thr_page_size;
684 /* Garbage thread count. */
685 SCLASS int _gc_count SCLASS_PRESET(0);
687 SCLASS umtx_t _mutex_static_lock;
688 SCLASS umtx_t _cond_static_lock;
689 SCLASS umtx_t _rwlock_static_lock;
690 SCLASS umtx_t _keytable_lock;
691 SCLASS umtx_t _thr_list_lock;
692 SCLASS umtx_t _thr_event_lock;
694 /* Undefine the storage class and preset specifiers: */
699 * Function prototype definitions.
702 int _thr_setthreaded(int);
703 int _mutex_cv_lock(pthread_mutex_t *);
704 int _mutex_cv_unlock(pthread_mutex_t *);
705 void _mutex_notify_priochange(struct pthread *, struct pthread *, int);
706 int _mutex_reinit(pthread_mutex_t *);
707 void _mutex_fork(struct pthread *curthread);
708 void _mutex_unlock_private(struct pthread *);
709 void _libpthread_init(struct pthread *);
710 void *_pthread_getspecific(pthread_key_t);
711 int _pthread_cond_init(pthread_cond_t *, const pthread_condattr_t *);
712 int _pthread_cond_destroy(pthread_cond_t *);
713 int _pthread_cond_wait(pthread_cond_t *, pthread_mutex_t *);
714 int _pthread_cond_timedwait(pthread_cond_t *, pthread_mutex_t *,
715 const struct timespec *);
716 int _pthread_cond_signal(pthread_cond_t *);
717 int _pthread_cond_broadcast(pthread_cond_t *);
718 int _pthread_key_create(pthread_key_t *, void (*) (void *));
719 int _pthread_key_delete(pthread_key_t);
720 int _pthread_mutex_destroy(pthread_mutex_t *);
721 int _pthread_mutex_init(pthread_mutex_t *, const pthread_mutexattr_t *);
722 int _pthread_mutex_lock(pthread_mutex_t *);
723 int _pthread_mutex_trylock(pthread_mutex_t *);
724 int _pthread_mutex_unlock(pthread_mutex_t *);
725 int _pthread_mutexattr_init(pthread_mutexattr_t *);
726 int _pthread_mutexattr_destroy(pthread_mutexattr_t *);
727 int _pthread_mutexattr_settype(pthread_mutexattr_t *, int);
728 int _pthread_once(pthread_once_t *, void (*) (void));
729 int _pthread_rwlock_init(pthread_rwlock_t *, const pthread_rwlockattr_t *);
730 int _pthread_rwlock_destroy (pthread_rwlock_t *);
731 struct pthread *_pthread_self(void);
732 int _pthread_setspecific(pthread_key_t, const void *);
733 void _pthread_testcancel(void);
734 void _pthread_yield(void);
735 void _pthread_cleanup_push(void (*routine) (void *), void *routine_arg);
736 void _pthread_cleanup_pop(int execute);
737 struct pthread *_thr_alloc(struct pthread *);
738 void _thread_exit(char *, int, char *) __dead2;
739 void _thr_exit_cleanup(void);
740 int _thr_ref_add(struct pthread *, struct pthread *, int);
741 void _thr_ref_delete(struct pthread *, struct pthread *);
742 void _thr_ref_delete_unlocked(struct pthread *, struct pthread *);
743 int _thr_find_thread(struct pthread *, struct pthread *, int);
744 void _thr_rtld_init(void);
745 void _thr_rtld_fini(void);
746 int _thr_stack_alloc(struct pthread_attr *);
747 void _thr_stack_free(struct pthread_attr *);
748 void _thr_free(struct pthread *, struct pthread *);
749 void _thr_gc(struct pthread *);
750 void _thread_cleanupspecific(void);
751 void _thread_dump_info(void);
752 void _thread_printf(int, const char *, ...);
753 void _thr_spinlock_init(void);
754 int _thr_cancel_enter(struct pthread *);
755 void _thr_cancel_leave(struct pthread *, int);
756 void _thr_signal_block(struct pthread *);
757 void _thr_signal_unblock(struct pthread *);
758 void _thr_signal_init(void);
759 void _thr_signal_deinit(void);
760 int _thr_send_sig(struct pthread *, int sig);
761 void _thr_list_init();
762 void _thr_hash_add(struct pthread *);
763 void _thr_hash_remove(struct pthread *);
764 struct pthread *_thr_hash_find(struct pthread *);
765 void _thr_link(struct pthread *curthread, struct pthread *thread);
766 void _thr_unlink(struct pthread *curthread, struct pthread *thread);
767 void _thr_suspend_check(struct pthread *curthread);
768 void _thr_assert_lock_level() __dead2;
769 void _thr_ast(struct pthread *);
770 int _thr_get_tid(void);
771 void _thr_report_creation(struct pthread *curthread,
772 struct pthread *newthread);
773 void _thr_report_death(struct pthread *curthread);
774 void _thread_bp_create(void);
775 void _thread_bp_death(void);
777 /* #include <sys/aio.h> */
779 int __sys_aio_suspend(const struct aiocb * const[], int, const struct timespec *);
782 /* #include <fcntl.h> */
784 int __sys_fcntl(int, int, ...);
785 int __sys_open(const char *, int, ...);
788 /* #include <sys/ioctl.h> */
790 int __sys_ioctl(int, unsigned long, ...);
793 /* #inclde <sched.h> */
795 int __sys_sched_yield(void);
798 /* #include <signal.h> */
800 int __sys_kill(pid_t, int);
801 int __sys_sigaction(int, const struct sigaction *, struct sigaction *);
802 int __sys_sigpending(sigset_t *);
803 int __sys_sigprocmask(int, const sigset_t *, sigset_t *);
804 int __sys_sigsuspend(const sigset_t *);
805 int __sys_sigreturn(ucontext_t *);
806 int __sys_sigaltstack(const struct sigaltstack *, struct sigaltstack *);
809 /* #include <sys/socket.h> */
810 #ifdef _SYS_SOCKET_H_
811 int __sys_accept(int, struct sockaddr *, socklen_t *);
812 int __sys_connect(int, const struct sockaddr *, socklen_t);
813 ssize_t __sys_recv(int, void *, size_t, int);
814 ssize_t __sys_recvfrom(int, void *, size_t, int, struct sockaddr *, socklen_t *);
815 ssize_t __sys_recvmsg(int, struct msghdr *, int);
816 int __sys_sendfile(int, int, off_t, size_t, struct sf_hdtr *,
818 ssize_t __sys_sendmsg(int, const struct msghdr *, int);
819 ssize_t __sys_sendto(int, const void *,size_t, int, const struct sockaddr *, socklen_t);
822 /* #include <sys/uio.h> */
824 ssize_t __sys_readv(int, const struct iovec *, int);
825 ssize_t __sys_writev(int, const struct iovec *, int);
828 /* #include <time.h> */
830 int __sys_nanosleep(const struct timespec *, struct timespec *);
833 /* #include <unistd.h> */
835 int __sys_close(int);
836 int __sys_execve(const char *, char * const *, char * const *);
837 int __sys_fork(void);
838 int __sys_fsync(int);
839 pid_t __sys_getpid(void);
840 int __sys_select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
841 ssize_t __sys_read(int, void *, size_t);
842 ssize_t __sys_write(int, const void *, size_t);
843 void __sys_exit(int);
844 int __sys_sigwait(const sigset_t *, int *);
845 int __sys_sigtimedwait(const sigset_t *, siginfo_t *,
846 const struct timespec *);
847 int __sys_sigwaitinfo(const sigset_t *set, siginfo_t *info);
850 /* #include <poll.h> */
852 int __sys_poll(struct pollfd *, unsigned, int);
855 /* #include <sys/mman.h> */
857 int __sys_msync(void *, size_t, int);
861 _thr_isthreaded(void)
863 return (__isthreaded != 0);
869 return (_thr_initial != 0);
873 _thr_check_init(void)
875 if (_thr_initial == 0)
881 #endif /* !_THR_PRIVATE_H */