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