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