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>.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice unmodified, this list of conditions, and the following
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.
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.
32 #ifndef _THR_PRIVATE_H
33 #define _THR_PRIVATE_H
38 #include <sys/types.h>
40 #include <sys/cdefs.h>
41 #include <sys/queue.h>
42 #include <sys/param.h>
43 #include <sys/cpuset.h>
44 #include <machine/atomic.h>
55 #define SYM_FB10(sym) __CONCAT(sym, _fb10)
56 #define SYM_FBP10(sym) __CONCAT(sym, _fbp10)
57 #define WEAK_REF(sym, alias) __weak_reference(sym, alias)
58 #define SYM_COMPAT(sym, impl, ver) __sym_compat(sym, impl, ver)
59 #define SYM_DEFAULT(sym, impl, ver) __sym_default(sym, impl, ver)
61 #define FB10_COMPAT(func, sym) \
62 WEAK_REF(func, SYM_FB10(sym)); \
63 SYM_COMPAT(sym, SYM_FB10(sym), FBSD_1.0)
65 #define FB10_COMPAT_PRIVATE(func, sym) \
66 WEAK_REF(func, SYM_FBP10(sym)); \
67 SYM_DEFAULT(sym, SYM_FBP10(sym), FBSDprivate_1.0)
69 #include "pthread_md.h"
71 #include "thread_db.h"
73 #ifdef _PTHREAD_FORCED_UNWIND
78 typedef TAILQ_HEAD(pthreadlist, pthread) pthreadlist;
79 typedef TAILQ_HEAD(atfork_head, pthread_atfork) atfork_head;
80 TAILQ_HEAD(mutex_queue, pthread_mutex);
82 /* Signal to do cancellation */
86 * Kernel fatal error handler macro.
88 #define PANIC(string) _thread_exit(__FILE__,__LINE__,string)
90 /* Output debug messages like this: */
91 #define stdout_debug(args...) _thread_printf(STDOUT_FILENO, ##args)
92 #define stderr_debug(args...) _thread_printf(STDERR_FILENO, ##args)
94 #ifdef _PTHREADS_INVARIANTS
95 #define THR_ASSERT(cond, msg) do { \
96 if (__predict_false(!(cond))) \
100 #define THR_ASSERT(cond, msg)
104 # define STATIC_LIB_REQUIRE(name)
106 # define STATIC_LIB_REQUIRE(name) __asm (".globl " #name)
109 #define TIMESPEC_ADD(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 >= 1000000000) { \
115 (dst)->tv_nsec -= 1000000000; \
119 #define TIMESPEC_SUB(dst, src, val) \
121 (dst)->tv_sec = (src)->tv_sec - (val)->tv_sec; \
122 (dst)->tv_nsec = (src)->tv_nsec - (val)->tv_nsec; \
123 if ((dst)->tv_nsec < 0) { \
125 (dst)->tv_nsec += 1000000000; \
129 /* XXX These values should be same as those defined in pthread.h */
130 #define THR_MUTEX_INITIALIZER ((struct pthread_mutex *)NULL)
131 #define THR_ADAPTIVE_MUTEX_INITIALIZER ((struct pthread_mutex *)1)
132 #define THR_MUTEX_DESTROYED ((struct pthread_mutex *)2)
133 #define THR_COND_INITIALIZER ((struct pthread_cond *)NULL)
134 #define THR_COND_DESTROYED ((struct pthread_cond *)1)
135 #define THR_RWLOCK_INITIALIZER ((struct pthread_rwlock *)NULL)
136 #define THR_RWLOCK_DESTROYED ((struct pthread_rwlock *)1)
138 #define PMUTEX_FLAG_TYPE_MASK 0x0ff
139 #define PMUTEX_FLAG_PRIVATE 0x100
140 #define PMUTEX_FLAG_DEFERED 0x200
141 #define PMUTEX_TYPE(mtxflags) ((mtxflags) & PMUTEX_FLAG_TYPE_MASK)
143 #define MAX_DEFER_WAITERS 50
145 struct pthread_mutex {
147 * Lock for accesses to this structure.
149 struct umutex m_lock;
151 struct pthread *m_owner;
156 * Link for all mutexes a thread currently owns.
158 TAILQ_ENTRY(pthread_mutex) m_qe;
161 struct pthread_mutex_attr {
162 enum pthread_mutextype m_type;
167 #define PTHREAD_MUTEXATTR_STATIC_INITIALIZER \
168 { PTHREAD_MUTEX_DEFAULT, PTHREAD_PRIO_NONE, 0, MUTEX_FLAGS_PRIVATE }
170 struct pthread_cond {
171 __uint32_t __has_user_waiters;
172 __uint32_t __has_kern_waiters;
174 __uint32_t __clock_id;
177 struct pthread_cond_attr {
182 struct pthread_barrier {
183 struct umutex b_lock;
185 volatile int64_t b_cycle;
186 volatile int b_count;
187 volatile int b_waiters;
190 struct pthread_barrierattr {
194 struct pthread_spinlock {
195 struct umutex s_lock;
199 * Flags for condition variables.
201 #define COND_FLAGS_PRIVATE 0x01
202 #define COND_FLAGS_INITED 0x02
203 #define COND_FLAGS_BUSY 0x04
206 * Cleanup definitions.
208 struct pthread_cleanup {
209 struct pthread_cleanup *prev;
210 void (*routine)(void *);
215 #define THR_CLEANUP_PUSH(td, func, arg) { \
216 struct pthread_cleanup __cup; \
218 __cup.routine = func; \
219 __cup.routine_arg = arg; \
221 __cup.prev = (td)->cleanup; \
222 (td)->cleanup = &__cup;
224 #define THR_CLEANUP_POP(td, exec) \
225 (td)->cleanup = __cup.prev; \
227 __cup.routine(__cup.routine_arg); \
230 struct pthread_atfork {
231 TAILQ_ENTRY(pthread_atfork) qe;
232 void (*prepare)(void);
233 void (*parent)(void);
237 struct pthread_attr {
238 #define pthread_attr_start_copy sched_policy
243 #define THR_STACK_USER 0x100 /* 0xFF reserved for <pthread.h> */
245 void *stackaddr_attr;
246 size_t stacksize_attr;
247 size_t guardsize_attr;
248 #define pthread_attr_end_copy cpuset
254 struct wake_addr *link;
260 TAILQ_HEAD(, pthread) sq_blocked;
261 SLIST_HEAD(, sleepqueue) sq_freeq;
262 LIST_ENTRY(sleepqueue) sq_hash;
263 SLIST_ENTRY(sleepqueue) sq_flink;
269 * Thread creation state attributes.
271 #define THR_CREATE_RUNNING 0
272 #define THR_CREATE_SUSPENDED 1
275 * Miscellaneous definitions.
277 #define THR_STACK_DEFAULT (sizeof(void *) / 4 * 1024 * 1024)
280 * Maximum size of initial thread's stack. This perhaps deserves to be larger
281 * than the stacks of other threads, since many applications are likely to run
282 * almost entirely on this stack.
284 #define THR_STACK_INITIAL (THR_STACK_DEFAULT * 2)
287 * Define priorities returned by kernel.
289 #define THR_MIN_PRIORITY (_thr_priorities[SCHED_OTHER-1].pri_min)
290 #define THR_MAX_PRIORITY (_thr_priorities[SCHED_OTHER-1].pri_max)
291 #define THR_DEF_PRIORITY (_thr_priorities[SCHED_OTHER-1].pri_default)
293 #define THR_MIN_RR_PRIORITY (_thr_priorities[SCHED_RR-1].pri_min)
294 #define THR_MAX_RR_PRIORITY (_thr_priorities[SCHED_RR-1].pri_max)
295 #define THR_DEF_RR_PRIORITY (_thr_priorities[SCHED_RR-1].pri_default)
297 /* XXX The SCHED_FIFO should have same priority range as SCHED_RR */
298 #define THR_MIN_FIFO_PRIORITY (_thr_priorities[SCHED_FIFO_1].pri_min)
299 #define THR_MAX_FIFO_PRIORITY (_thr_priorities[SCHED_FIFO-1].pri_max)
300 #define THR_DEF_FIFO_PRIORITY (_thr_priorities[SCHED_FIFO-1].pri_default)
302 struct pthread_prio {
308 struct pthread_rwlockattr {
312 struct pthread_rwlock {
314 struct pthread *owner;
325 struct pthread_specific_elem {
331 volatile int allocated;
333 void (*destructor)(void *);
337 * lwpid_t is 32bit but kernel thr API exports tid as long type
338 * in very earily date.
340 #define TID(thread) ((uint32_t) ((thread)->tid))
346 /* Kernel thread id. */
348 #define TID_TERMINATED 1
351 * Lock for accesses to this thread structure.
355 /* Internal condition variable cycle number. */
358 /* How many low level locks the thread held. */
362 * Set to non-zero when this thread has entered a critical
363 * region. We allow for recursive entries into critical regions.
367 /* Signal blocked counter. */
370 /* Queue entry for list of all threads. */
371 TAILQ_ENTRY(pthread) tle; /* link for all threads in process */
373 /* Queue entry for GC lists. */
374 TAILQ_ENTRY(pthread) gcle;
376 /* Hash queue entry. */
377 LIST_ENTRY(pthread) hle;
379 /* Sleep queue entry */
380 TAILQ_ENTRY(pthread) wle;
382 /* Threads reference count. */
386 * Thread start routine, argument, stack pointer and thread
389 void *(*start_routine)(void *);
391 struct pthread_attr attr;
393 #define SHOULD_CANCEL(thr) \
394 ((thr)->cancel_pending && (thr)->cancel_enable && \
395 (thr)->no_cancel == 0)
397 /* Cancellation is enabled */
400 /* Cancellation request is pending */
403 /* Thread is at cancellation point */
406 /* Cancellation is temporarily disabled */
409 /* Asynchronouse cancellation is enabled */
412 /* Cancellation is in progress */
415 /* Thread temporary signal mask. */
418 /* Thread should unblock SIGCANCEL. */
419 int unblock_sigcancel;
421 /* In sigsuspend state */
424 /* deferred signal info */
425 siginfo_t deferred_siginfo;
427 /* signal mask to restore. */
428 sigset_t deferred_sigmask;
430 /* the sigaction should be used for deferred signal. */
431 struct sigaction deferred_sigact;
433 /* Force new thread to exit. */
437 enum pthread_state state;
440 * Error variable used instead of errno. The function __error()
441 * returns a pointer to this.
446 * The joiner is the thread that is joining to this thread. The
447 * join status keeps track of a join operation to another thread.
449 struct pthread *joiner;
451 /* Miscellaneous flags; only set with scheduling lock held. */
453 #define THR_FLAGS_PRIVATE 0x0001
454 #define THR_FLAGS_NEED_SUSPEND 0x0002 /* thread should be suspended */
455 #define THR_FLAGS_SUSPENDED 0x0004 /* thread is suspended */
456 #define THR_FLAGS_DETACHED 0x0008 /* thread is detached */
458 /* Thread list flags; only set with thread list lock held. */
460 #define TLFLAGS_GC_SAFE 0x0001 /* thread safe for cleaning */
461 #define TLFLAGS_IN_TDLIST 0x0002 /* thread in all thread list */
462 #define TLFLAGS_IN_GCLIST 0x0004 /* thread in gc list */
464 /* Queue of currently owned NORMAL or PRIO_INHERIT type mutexes. */
465 struct mutex_queue mutexq;
467 /* Queue of all owned PRIO_PROTECT mutexes. */
468 struct mutex_queue pp_mutexq;
471 struct pthread_specific_elem *specific;
472 int specific_data_count;
474 /* Number rwlocks rdlocks held. */
478 * Current locks bitmap for rtld. */
481 /* Thread control block */
484 /* Cleanup handlers Link List */
485 struct pthread_cleanup *cleanup;
487 #ifdef _PTHREAD_FORCED_UNWIND
488 struct _Unwind_Exception ex;
489 void *unwind_stackend;
494 * Magic value to help recognize a valid thread structure
495 * from an invalid one:
497 #define THR_MAGIC ((u_int32_t) 0xd09ba115)
500 /* Enable event reporting */
507 td_event_msg_t event_buf;
509 struct wake_addr *wake_addr;
510 #define WAKE_ADDR(td) ((td)->wake_addr)
513 struct sleepqueue *sleepqueue;
518 /* Referenced mutex. */
519 struct pthread_mutex *mutex_obj;
521 /* Thread will sleep. */
524 /* Number of threads deferred. */
527 /* Deferred threads from pthread_cond_signal. */
528 unsigned int *defer_waiters[MAX_DEFER_WAITERS];
531 #define THR_SHOULD_GC(thrd) \
532 ((thrd)->refcount == 0 && (thrd)->state == PS_DEAD && \
533 ((thrd)->flags & THR_FLAGS_DETACHED) != 0)
535 #define THR_IN_CRITICAL(thrd) \
536 (((thrd)->locklevel > 0) || \
537 ((thrd)->critical_count > 0))
539 #define THR_CRITICAL_ENTER(thrd) \
540 (thrd)->critical_count++
542 #define THR_CRITICAL_LEAVE(thrd) \
544 (thrd)->critical_count--; \
548 #define THR_UMUTEX_TRYLOCK(thrd, lck) \
549 _thr_umutex_trylock((lck), TID(thrd))
551 #define THR_UMUTEX_LOCK(thrd, lck) \
552 _thr_umutex_lock((lck), TID(thrd))
554 #define THR_UMUTEX_TIMEDLOCK(thrd, lck, timo) \
555 _thr_umutex_timedlock((lck), TID(thrd), (timo))
557 #define THR_UMUTEX_UNLOCK(thrd, lck) \
558 _thr_umutex_unlock((lck), TID(thrd))
560 #define THR_LOCK_ACQUIRE(thrd, lck) \
562 (thrd)->locklevel++; \
563 _thr_umutex_lock(lck, TID(thrd)); \
566 #define THR_LOCK_ACQUIRE_SPIN(thrd, lck) \
568 (thrd)->locklevel++; \
569 _thr_umutex_lock_spin(lck, TID(thrd)); \
572 #ifdef _PTHREADS_INVARIANTS
573 #define THR_ASSERT_LOCKLEVEL(thrd) \
575 if (__predict_false((thrd)->locklevel <= 0)) \
576 _thr_assert_lock_level(); \
579 #define THR_ASSERT_LOCKLEVEL(thrd)
582 #define THR_LOCK_RELEASE(thrd, lck) \
584 THR_ASSERT_LOCKLEVEL(thrd); \
585 _thr_umutex_unlock((lck), TID(thrd)); \
586 (thrd)->locklevel--; \
590 #define THR_LOCK(curthrd) THR_LOCK_ACQUIRE(curthrd, &(curthrd)->lock)
591 #define THR_UNLOCK(curthrd) THR_LOCK_RELEASE(curthrd, &(curthrd)->lock)
592 #define THR_THREAD_LOCK(curthrd, thr) THR_LOCK_ACQUIRE(curthrd, &(thr)->lock)
593 #define THR_THREAD_UNLOCK(curthrd, thr) THR_LOCK_RELEASE(curthrd, &(thr)->lock)
595 #define THREAD_LIST_RDLOCK(curthrd) \
597 (curthrd)->locklevel++; \
598 _thr_rwl_rdlock(&_thr_list_lock); \
601 #define THREAD_LIST_WRLOCK(curthrd) \
603 (curthrd)->locklevel++; \
604 _thr_rwl_wrlock(&_thr_list_lock); \
607 #define THREAD_LIST_UNLOCK(curthrd) \
609 _thr_rwl_unlock(&_thr_list_lock); \
610 (curthrd)->locklevel--; \
615 * Macros to insert/remove threads to the all thread list and
618 #define THR_LIST_ADD(thrd) do { \
619 if (((thrd)->tlflags & TLFLAGS_IN_TDLIST) == 0) { \
620 TAILQ_INSERT_HEAD(&_thread_list, thrd, tle); \
621 _thr_hash_add(thrd); \
622 (thrd)->tlflags |= TLFLAGS_IN_TDLIST; \
625 #define THR_LIST_REMOVE(thrd) do { \
626 if (((thrd)->tlflags & TLFLAGS_IN_TDLIST) != 0) { \
627 TAILQ_REMOVE(&_thread_list, thrd, tle); \
628 _thr_hash_remove(thrd); \
629 (thrd)->tlflags &= ~TLFLAGS_IN_TDLIST; \
632 #define THR_GCLIST_ADD(thrd) do { \
633 if (((thrd)->tlflags & TLFLAGS_IN_GCLIST) == 0) { \
634 TAILQ_INSERT_HEAD(&_thread_gc_list, thrd, gcle);\
635 (thrd)->tlflags |= TLFLAGS_IN_GCLIST; \
639 #define THR_GCLIST_REMOVE(thrd) do { \
640 if (((thrd)->tlflags & TLFLAGS_IN_GCLIST) != 0) { \
641 TAILQ_REMOVE(&_thread_gc_list, thrd, gcle); \
642 (thrd)->tlflags &= ~TLFLAGS_IN_GCLIST; \
647 #define THR_REF_ADD(curthread, pthread) { \
648 THR_CRITICAL_ENTER(curthread); \
649 pthread->refcount++; \
652 #define THR_REF_DEL(curthread, pthread) { \
653 pthread->refcount--; \
654 THR_CRITICAL_LEAVE(curthread); \
657 #define GC_NEEDED() (_gc_count >= 5)
659 #define SHOULD_REPORT_EVENT(curthr, e) \
660 (curthr->report_events && \
661 (((curthr)->event_mask | _thread_event_mask ) & e) != 0)
663 extern int __isthreaded;
666 * Global variables for the pthread kernel.
669 extern char *_usrstack __hidden;
670 extern struct pthread *_thr_initial __hidden;
673 extern int _libthr_debug;
674 extern int _thread_event_mask;
675 extern struct pthread *_thread_last_event;
677 /* List of all threads: */
678 extern pthreadlist _thread_list;
680 /* List of threads needing GC: */
681 extern pthreadlist _thread_gc_list __hidden;
683 extern int _thread_active_threads;
684 extern atfork_head _thr_atfork_list __hidden;
685 extern struct urwlock _thr_atfork_lock __hidden;
687 /* Default thread attributes: */
688 extern struct pthread_attr _pthread_attr_default __hidden;
690 /* Default mutex attributes: */
691 extern struct pthread_mutex_attr _pthread_mutexattr_default __hidden;
692 extern struct pthread_mutex_attr _pthread_mutexattr_adaptive_default __hidden;
694 /* Default condition variable attributes: */
695 extern struct pthread_cond_attr _pthread_condattr_default __hidden;
697 extern struct pthread_prio _thr_priorities[] __hidden;
699 extern pid_t _thr_pid __hidden;
700 extern int _thr_is_smp __hidden;
702 extern size_t _thr_guard_default __hidden;
703 extern size_t _thr_stack_default __hidden;
704 extern size_t _thr_stack_initial __hidden;
705 extern int _thr_page_size __hidden;
706 extern int _thr_spinloops __hidden;
707 extern int _thr_yieldloops __hidden;
709 /* Garbage thread count. */
710 extern int _gc_count __hidden;
712 extern struct umutex _mutex_static_lock __hidden;
713 extern struct umutex _cond_static_lock __hidden;
714 extern struct umutex _rwlock_static_lock __hidden;
715 extern struct umutex _keytable_lock __hidden;
716 extern struct urwlock _thr_list_lock __hidden;
717 extern struct umutex _thr_event_lock __hidden;
720 * Function prototype definitions.
723 int _thr_setthreaded(int) __hidden;
724 int _mutex_cv_lock(struct pthread_mutex *, int count) __hidden;
725 int _mutex_cv_unlock(struct pthread_mutex *, int *count) __hidden;
726 int _mutex_cv_attach(struct pthread_mutex *, int count) __hidden;
727 int _mutex_cv_detach(struct pthread_mutex *, int *count) __hidden;
728 int _mutex_owned(struct pthread *, const struct pthread_mutex *) __hidden;
729 int _mutex_reinit(pthread_mutex_t *) __hidden;
730 void _mutex_fork(struct pthread *curthread) __hidden;
731 void _libpthread_init(struct pthread *) __hidden;
732 struct pthread *_thr_alloc(struct pthread *) __hidden;
733 void _thread_exit(const char *, int, const char *) __hidden __dead2;
734 int _thr_ref_add(struct pthread *, struct pthread *, int) __hidden;
735 void _thr_ref_delete(struct pthread *, struct pthread *) __hidden;
736 void _thr_ref_delete_unlocked(struct pthread *, struct pthread *) __hidden;
737 int _thr_find_thread(struct pthread *, struct pthread *, int) __hidden;
738 void _thr_rtld_init(void) __hidden;
739 void _thr_rtld_fini(void) __hidden;
740 void _thr_rtld_postfork_child(void) __hidden;
741 int _thr_stack_alloc(struct pthread_attr *) __hidden;
742 void _thr_stack_free(struct pthread_attr *) __hidden;
743 void _thr_free(struct pthread *, struct pthread *) __hidden;
744 void _thr_gc(struct pthread *) __hidden;
745 void _thread_cleanupspecific(void) __hidden;
746 void _thread_printf(int, const char *, ...) __hidden;
747 void _thr_spinlock_init(void) __hidden;
748 void _thr_cancel_enter(struct pthread *) __hidden;
749 void _thr_cancel_enter2(struct pthread *, int) __hidden;
750 void _thr_cancel_leave(struct pthread *, int) __hidden;
751 void _thr_testcancel(struct pthread *) __hidden;
752 void _thr_signal_block(struct pthread *) __hidden;
753 void _thr_signal_unblock(struct pthread *) __hidden;
754 void _thr_signal_init(void) __hidden;
755 void _thr_signal_deinit(void) __hidden;
756 int _thr_send_sig(struct pthread *, int sig) __hidden;
757 void _thr_list_init(void) __hidden;
758 void _thr_hash_add(struct pthread *) __hidden;
759 void _thr_hash_remove(struct pthread *) __hidden;
760 struct pthread *_thr_hash_find(struct pthread *) __hidden;
761 void _thr_link(struct pthread *, struct pthread *) __hidden;
762 void _thr_unlink(struct pthread *, struct pthread *) __hidden;
763 void _thr_assert_lock_level(void) __hidden __dead2;
764 void _thr_ast(struct pthread *) __hidden;
765 void _thr_once_init(void) __hidden;
766 void _thr_report_creation(struct pthread *curthread,
767 struct pthread *newthread) __hidden;
768 void _thr_report_death(struct pthread *curthread) __hidden;
769 int _thr_getscheduler(lwpid_t, int *, struct sched_param *) __hidden;
770 int _thr_setscheduler(lwpid_t, int, const struct sched_param *) __hidden;
771 void _thr_signal_prefork(void) __hidden;
772 void _thr_signal_postfork(void) __hidden;
773 void _thr_signal_postfork_child(void) __hidden;
774 void _thr_try_gc(struct pthread *, struct pthread *) __hidden;
775 int _rtp_to_schedparam(const struct rtprio *rtp, int *policy,
776 struct sched_param *param) __hidden;
777 int _schedparam_to_rtp(int policy, const struct sched_param *param,
778 struct rtprio *rtp) __hidden;
779 void _thread_bp_create(void);
780 void _thread_bp_death(void);
781 int _sched_yield(void);
783 void _pthread_cleanup_push(void (*)(void *), void *);
784 void _pthread_cleanup_pop(int);
785 void _pthread_exit_mask(void *status, sigset_t *mask) __dead2 __hidden;
786 void _pthread_cancel_enter(int maycancel);
787 void _pthread_cancel_leave(int maycancel);
789 /* #include <fcntl.h> */
791 int __sys_fcntl(int, int, ...);
792 int __sys_open(const char *, int, ...);
793 int __sys_openat(int, const char *, int, ...);
796 /* #include <signal.h> */
798 int __sys_kill(pid_t, int);
799 int __sys_sigaction(int, const struct sigaction *, struct sigaction *);
800 int __sys_sigpending(sigset_t *);
801 int __sys_sigprocmask(int, const sigset_t *, sigset_t *);
802 int __sys_sigsuspend(const sigset_t *);
803 int __sys_sigreturn(const ucontext_t *);
804 int __sys_sigaltstack(const struct sigaltstack *, struct sigaltstack *);
805 int __sys_sigwait(const sigset_t *, int *);
806 int __sys_sigtimedwait(const sigset_t *, siginfo_t *,
807 const struct timespec *);
808 int __sys_sigwaitinfo(const sigset_t *set, siginfo_t *info);
811 /* #include <time.h> */
813 int __sys_nanosleep(const struct timespec *, struct timespec *);
816 /* #include <sys/ucontext.h> */
817 #ifdef _SYS_UCONTEXT_H_
818 int __sys_setcontext(const ucontext_t *ucp);
819 int __sys_swapcontext(ucontext_t *oucp, const ucontext_t *ucp);
822 /* #include <unistd.h> */
824 int __sys_close(int);
825 int __sys_fork(void);
826 pid_t __sys_getpid(void);
827 ssize_t __sys_read(int, void *, size_t);
828 ssize_t __sys_write(int, const void *, size_t);
829 void __sys_exit(int);
832 int _umtx_op_err(void *, int op, u_long, void *, void *) __hidden;
835 _thr_isthreaded(void)
837 return (__isthreaded != 0);
843 return (_thr_initial != NULL);
847 _thr_check_init(void)
849 if (_thr_initial == NULL)
850 _libpthread_init(NULL);
853 struct wake_addr *_thr_alloc_wake_addr(void);
854 void _thr_release_wake_addr(struct wake_addr *);
855 int _thr_sleep(struct pthread *, int, const struct timespec *);
857 void _thr_wake_addr_init(void) __hidden;
860 _thr_clear_wake(struct pthread *td)
862 td->wake_addr->value = 0;
866 _thr_is_woken(struct pthread *td)
868 return td->wake_addr->value != 0;
872 _thr_set_wake(unsigned int *waddr)
875 _thr_umtx_wake(waddr, INT_MAX, 0);
878 void _thr_wake_all(unsigned int *waddrs[], int) __hidden;
880 static inline struct pthread *
881 _sleepq_first(struct sleepqueue *sq)
883 return TAILQ_FIRST(&sq->sq_blocked);
886 void _sleepq_init(void) __hidden;
887 struct sleepqueue *_sleepq_alloc(void) __hidden;
888 void _sleepq_free(struct sleepqueue *) __hidden;
889 void _sleepq_lock(void *) __hidden;
890 void _sleepq_unlock(void *) __hidden;
891 struct sleepqueue *_sleepq_lookup(void *) __hidden;
892 void _sleepq_add(void *, struct pthread *) __hidden;
893 int _sleepq_remove(struct sleepqueue *, struct pthread *) __hidden;
894 void _sleepq_drop(struct sleepqueue *,
895 void (*cb)(struct pthread *, void *arg), void *) __hidden;
898 void __pthread_cxa_finalize(struct dl_phdr_info *phdr_info);
899 void _thr_tsd_unload(struct dl_phdr_info *phdr_info) __hidden;
900 void _thr_sigact_unload(struct dl_phdr_info *phdr_info) __hidden;
901 void _thr_stack_fix_protection(struct pthread *thrd);
905 #endif /* !_THR_PRIVATE_H */