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