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