xref: /freebsd/lib/libthr/thread/thr_private.h (revision 1e413cf93298b5b97441a21d9a50fdcd0ee9945e)
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$
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 
61 typedef TAILQ_HEAD(pthreadlist, pthread) pthreadlist;
62 typedef TAILQ_HEAD(atfork_head, pthread_atfork) atfork_head;
63 TAILQ_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(STDERR_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 
112 struct 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 	int				m_spinloops;
123 	int				m_yieldloops;
124 	/*
125 	 * Link for all mutexes a thread currently owns.
126 	 */
127 	TAILQ_ENTRY(pthread_mutex)	m_qe;
128 };
129 
130 /*
131  * Flags for mutexes.
132  */
133 #define MUTEX_FLAGS_PRIVATE	0x01
134 #define MUTEX_FLAGS_INITED	0x02
135 #define MUTEX_FLAGS_BUSY	0x04
136 
137 struct pthread_mutex_attr {
138 	enum pthread_mutextype	m_type;
139 	int			m_protocol;
140 	int			m_ceiling;
141 	int			m_flags;
142 };
143 
144 #define PTHREAD_MUTEXATTR_STATIC_INITIALIZER \
145 	{ PTHREAD_MUTEX_DEFAULT, PTHREAD_PRIO_NONE, 0, MUTEX_FLAGS_PRIVATE }
146 
147 struct pthread_cond {
148 	struct umutex	c_lock;
149 	struct ucond	c_kerncv;
150 	int		c_pshared;
151 	int		c_clockid;
152 };
153 
154 struct pthread_cond_attr {
155 	int		c_pshared;
156 	int		c_clockid;
157 };
158 
159 struct pthread_barrier {
160 	struct umutex		b_lock;
161 	struct ucond		b_cv;
162 	volatile int64_t	b_cycle;
163 	volatile int		b_count;
164 	volatile int		b_waiters;
165 };
166 
167 struct pthread_barrierattr {
168 	int		pshared;
169 };
170 
171 struct pthread_spinlock {
172 	struct umutex	s_lock;
173 };
174 
175 /*
176  * Flags for condition variables.
177  */
178 #define COND_FLAGS_PRIVATE	0x01
179 #define COND_FLAGS_INITED	0x02
180 #define COND_FLAGS_BUSY		0x04
181 
182 /*
183  * Cleanup definitions.
184  */
185 struct pthread_cleanup {
186 	struct pthread_cleanup	*next;
187 	void			(*routine)(void *args);
188 	void			*routine_arg;
189 	int			onstack;
190 };
191 
192 #define	THR_CLEANUP_PUSH(td, func, arg) {		\
193 	struct pthread_cleanup __cup;			\
194 							\
195 	__cup.routine = func;				\
196 	__cup.routine_arg = arg;			\
197 	__cup.onstack = 1;				\
198 	__cup.next = (td)->cleanup;			\
199 	(td)->cleanup = &__cup;
200 
201 #define	THR_CLEANUP_POP(td, exec)			\
202 	(td)->cleanup = __cup.next;			\
203 	if ((exec) != 0)				\
204 		__cup.routine(__cup.routine_arg);	\
205 }
206 
207 struct pthread_atfork {
208 	TAILQ_ENTRY(pthread_atfork) qe;
209 	void (*prepare)(void);
210 	void (*parent)(void);
211 	void (*child)(void);
212 };
213 
214 struct pthread_attr {
215 	int	sched_policy;
216 	int	sched_inherit;
217 	int	prio;
218 	int	suspend;
219 #define	THR_STACK_USER		0x100	/* 0xFF reserved for <pthread.h> */
220 	int	flags;
221 	void	*stackaddr_attr;
222 	size_t	stacksize_attr;
223 	size_t	guardsize_attr;
224 };
225 
226 /*
227  * Thread creation state attributes.
228  */
229 #define THR_CREATE_RUNNING		0
230 #define THR_CREATE_SUSPENDED		1
231 
232 /*
233  * Miscellaneous definitions.
234  */
235 #define THR_STACK_DEFAULT		(sizeof(void *) / 4 * 1024 * 1024)
236 
237 /*
238  * Maximum size of initial thread's stack.  This perhaps deserves to be larger
239  * than the stacks of other threads, since many applications are likely to run
240  * almost entirely on this stack.
241  */
242 #define THR_STACK_INITIAL		(THR_STACK_DEFAULT * 2)
243 
244 /*
245  * Define priorities returned by kernel.
246  */
247 #define THR_MIN_PRIORITY		(_thr_priorities[SCHED_OTHER-1].pri_min)
248 #define THR_MAX_PRIORITY		(_thr_priorities[SCHED_OTHER-1].pri_max)
249 #define THR_DEF_PRIORITY		(_thr_priorities[SCHED_OTHER-1].pri_default)
250 
251 #define THR_MIN_RR_PRIORITY		(_thr_priorities[SCHED_RR-1].pri_min)
252 #define THR_MAX_RR_PRIORITY		(_thr_priorities[SCHED_RR-1].pri_max)
253 #define THR_DEF_RR_PRIORITY		(_thr_priorities[SCHED_RR-1].pri_default)
254 
255 /* XXX The SCHED_FIFO should have same priority range as SCHED_RR */
256 #define THR_MIN_FIFO_PRIORITY		(_thr_priorities[SCHED_FIFO_1].pri_min)
257 #define THR_MAX_FIFO_PRIORITY		(_thr_priorities[SCHED_FIFO-1].pri_max)
258 #define THR_DEF_FIFO_PRIORITY		(_thr_priorities[SCHED_FIFO-1].pri_default)
259 
260 struct pthread_prio {
261 	int	pri_min;
262 	int	pri_max;
263 	int	pri_default;
264 };
265 
266 struct pthread_rwlockattr {
267 	int		pshared;
268 };
269 
270 struct pthread_rwlock {
271 	pthread_mutex_t	lock;	/* monitor lock */
272 	pthread_cond_t	read_signal;
273 	pthread_cond_t	write_signal;
274 	int		state;	/* 0 = idle  >0 = # of readers  -1 = writer */
275 	int		blocked_writers;
276 };
277 
278 /*
279  * Thread states.
280  */
281 enum pthread_state {
282 	PS_RUNNING,
283 	PS_DEAD
284 };
285 
286 struct pthread_specific_elem {
287 	const void	*data;
288 	int		seqno;
289 };
290 
291 struct pthread_key {
292 	volatile int	allocated;
293 	int		seqno;
294 	void            (*destructor)(void *);
295 };
296 
297 /*
298  * lwpid_t is 32bit but kernel thr API exports tid as long type
299  * in very earily date.
300  */
301 #define TID(thread)	((uint32_t) ((thread)->tid))
302 
303 /*
304  * Thread structure.
305  */
306 struct pthread {
307 	/* Kernel thread id. */
308 	long			tid;
309 #define	TID_TERMINATED		1
310 
311 	/*
312 	 * Lock for accesses to this thread structure.
313 	 */
314 	struct umutex		lock;
315 
316 	/* Internal condition variable cycle number. */
317 	long			cycle;
318 
319 	/* How many low level locks the thread held. */
320 	int			locklevel;
321 
322 	/*
323 	 * Set to non-zero when this thread has entered a critical
324 	 * region.  We allow for recursive entries into critical regions.
325 	 */
326 	int			critical_count;
327 
328 	/* Signal blocked counter. */
329 	int			sigblock;
330 
331 	/* Queue entry for list of all threads. */
332 	TAILQ_ENTRY(pthread)	tle;	/* link for all threads in process */
333 
334 	/* Queue entry for GC lists. */
335 	TAILQ_ENTRY(pthread)	gcle;
336 
337 	/* Hash queue entry. */
338 	LIST_ENTRY(pthread)	hle;
339 
340 	/* Threads reference count. */
341 	int			refcount;
342 
343 	/*
344 	 * Thread start routine, argument, stack pointer and thread
345 	 * attributes.
346 	 */
347 	void			*(*start_routine)(void *);
348 	void			*arg;
349 	struct pthread_attr	attr;
350 
351 #define	SHOULD_CANCEL(thr)					\
352 	((thr)->cancel_pending &&				\
353 	 ((thr)->cancel_point || (thr)->cancel_async) &&	\
354 	 (thr)->cancel_enable && (thr)->cancelling == 0)
355 
356 	/* Cancellation is enabled */
357 	int			cancel_enable;
358 
359 	/* Cancellation request is pending */
360 	int			cancel_pending;
361 
362 	/* Thread is at cancellation point */
363 	int			cancel_point;
364 
365 	/* Cancellation should be synchoronized */
366 	int			cancel_defer;
367 
368 	/* Asynchronouse cancellation is enabled */
369 	int			cancel_async;
370 
371 	/* Cancellation is in progress */
372 	int			cancelling;
373 
374 	/* Thread temporary signal mask. */
375 	sigset_t		sigmask;
376 
377 	/* Thread state: */
378 	enum pthread_state 	state;
379 
380 	/*
381 	 * Error variable used instead of errno. The function __error()
382 	 * returns a pointer to this.
383 	 */
384 	int			error;
385 
386 	/*
387 	 * The joiner is the thread that is joining to this thread.  The
388 	 * join status keeps track of a join operation to another thread.
389 	 */
390 	struct pthread		*joiner;
391 
392 	/* Miscellaneous flags; only set with scheduling lock held. */
393 	int			flags;
394 #define THR_FLAGS_PRIVATE	0x0001
395 #define	THR_FLAGS_NEED_SUSPEND	0x0002	/* thread should be suspended */
396 #define	THR_FLAGS_SUSPENDED	0x0004	/* thread is suspended */
397 
398 	/* Thread list flags; only set with thread list lock held. */
399 	int			tlflags;
400 #define	TLFLAGS_GC_SAFE		0x0001	/* thread safe for cleaning */
401 #define	TLFLAGS_IN_TDLIST	0x0002	/* thread in all thread list */
402 #define	TLFLAGS_IN_GCLIST	0x0004	/* thread in gc list */
403 #define	TLFLAGS_DETACHED	0x0008	/* thread is detached */
404 
405 	/* Queue of currently owned NORMAL or PRIO_INHERIT type mutexes. */
406 	struct mutex_queue	mutexq;
407 
408 	/* Queue of all owned PRIO_PROTECT mutexes. */
409 	struct mutex_queue	pp_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_UMUTEX_TRYLOCK(thrd, lck)			\
457 	_thr_umutex_trylock((lck), TID(thrd))
458 
459 #define	THR_UMUTEX_LOCK(thrd, lck)			\
460 	_thr_umutex_lock((lck), TID(thrd))
461 
462 #define	THR_UMUTEX_TIMEDLOCK(thrd, lck, timo)		\
463 	_thr_umutex_timedlock((lck), TID(thrd), (timo))
464 
465 #define	THR_UMUTEX_UNLOCK(thrd, lck)			\
466 	_thr_umutex_unlock((lck), TID(thrd))
467 
468 #define	THR_LOCK_ACQUIRE(thrd, lck)			\
469 do {							\
470 	(thrd)->locklevel++;				\
471 	_thr_umutex_lock(lck, TID(thrd));		\
472 } while (0)
473 
474 #ifdef	_PTHREADS_INVARIANTS
475 #define	THR_ASSERT_LOCKLEVEL(thrd)			\
476 do {							\
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)			\
485 do {							\
486 	THR_ASSERT_LOCKLEVEL(thrd);			\
487 	_thr_umutex_unlock((lck), TID(thrd));		\
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)				\
498 do {								\
499 	THR_LOCK_ACQUIRE((curthrd), &_thr_list_lock);		\
500 } while (0)
501 
502 #define	THREAD_LIST_UNLOCK(curthrd)				\
503 do {								\
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 
546 extern int __isthreaded;
547 
548 /*
549  * Global variables for the pthread kernel.
550  */
551 
552 extern char		*_usrstack __hidden;
553 extern struct pthread	*_thr_initial __hidden;
554 
555 /* For debugger */
556 extern int		_libthr_debug;
557 extern int		_thread_event_mask;
558 extern struct pthread	*_thread_last_event;
559 
560 /* List of all threads: */
561 extern pthreadlist	_thread_list;
562 
563 /* List of threads needing GC: */
564 extern pthreadlist	_thread_gc_list __hidden;
565 
566 extern int		_thread_active_threads;
567 extern atfork_head	_thr_atfork_list __hidden;
568 extern struct umutex	_thr_atfork_lock __hidden;
569 
570 /* Default thread attributes: */
571 extern struct pthread_attr _pthread_attr_default __hidden;
572 
573 /* Default mutex attributes: */
574 extern struct pthread_mutex_attr _pthread_mutexattr_default __hidden;
575 
576 /* Default condition variable attributes: */
577 extern struct pthread_cond_attr _pthread_condattr_default __hidden;
578 
579 extern struct pthread_prio _thr_priorities[] __hidden;
580 
581 extern pid_t	_thr_pid __hidden;
582 extern int	_thr_is_smp __hidden;
583 
584 extern size_t	_thr_guard_default __hidden;
585 extern size_t	_thr_stack_default __hidden;
586 extern size_t	_thr_stack_initial __hidden;
587 extern int	_thr_page_size __hidden;
588 extern int	_thr_spinloops __hidden;
589 extern int	_thr_yieldloops __hidden;
590 
591 /* Garbage thread count. */
592 extern int	_gc_count __hidden;
593 
594 extern struct umutex	_mutex_static_lock __hidden;
595 extern struct umutex	_cond_static_lock __hidden;
596 extern struct umutex	_rwlock_static_lock __hidden;
597 extern struct umutex	_keytable_lock __hidden;
598 extern struct umutex	_thr_list_lock __hidden;
599 extern struct umutex	_thr_event_lock __hidden;
600 
601 /*
602  * Function prototype definitions.
603  */
604 __BEGIN_DECLS
605 int	_thr_setthreaded(int) __hidden;
606 int	_mutex_cv_lock(pthread_mutex_t *, int count) __hidden;
607 int	_mutex_cv_unlock(pthread_mutex_t *, int *count) __hidden;
608 int	_mutex_reinit(pthread_mutex_t *) __hidden;
609 void	_mutex_fork(struct pthread *curthread) __hidden;
610 void	_mutex_unlock_private(struct pthread *) __hidden;
611 void	_libpthread_init(struct pthread *) __hidden;
612 struct pthread *_thr_alloc(struct pthread *) __hidden;
613 void	_thread_exit(const char *, int, const char *) __hidden __dead2;
614 void	_thr_exit_cleanup(void) __hidden;
615 int	_thr_ref_add(struct pthread *, struct pthread *, int) __hidden;
616 void	_thr_ref_delete(struct pthread *, struct pthread *) __hidden;
617 void	_thr_ref_delete_unlocked(struct pthread *, struct pthread *) __hidden;
618 int	_thr_find_thread(struct pthread *, struct pthread *, int) __hidden;
619 void	_thr_rtld_init(void) __hidden;
620 void	_thr_rtld_fini(void) __hidden;
621 int	_thr_stack_alloc(struct pthread_attr *) __hidden;
622 void	_thr_stack_free(struct pthread_attr *) __hidden;
623 void	_thr_free(struct pthread *, struct pthread *) __hidden;
624 void	_thr_gc(struct pthread *) __hidden;
625 void    _thread_cleanupspecific(void) __hidden;
626 void    _thread_dump_info(void) __hidden;
627 void	_thread_printf(int, const char *, ...) __hidden;
628 void	_thr_spinlock_init(void) __hidden;
629 void	_thr_cancel_enter(struct pthread *) __hidden;
630 void	_thr_cancel_leave(struct pthread *) __hidden;
631 void	_thr_cancel_enter_defer(struct pthread *) __hidden;
632 void	_thr_cancel_leave_defer(struct pthread *, int) __hidden;
633 void	_thr_testcancel(struct pthread *) __hidden;
634 void	_thr_signal_block(struct pthread *) __hidden;
635 void	_thr_signal_unblock(struct pthread *) __hidden;
636 void	_thr_signal_init(void) __hidden;
637 void	_thr_signal_deinit(void) __hidden;
638 int	_thr_send_sig(struct pthread *, int sig) __hidden;
639 void	_thr_list_init(void) __hidden;
640 void	_thr_hash_add(struct pthread *) __hidden;
641 void	_thr_hash_remove(struct pthread *) __hidden;
642 struct pthread *_thr_hash_find(struct pthread *) __hidden;
643 void	_thr_link(struct pthread *, struct pthread *) __hidden;
644 void	_thr_unlink(struct pthread *, struct pthread *) __hidden;
645 void	_thr_suspend_check(struct pthread *) __hidden;
646 void	_thr_assert_lock_level(void) __hidden __dead2;
647 void	_thr_ast(struct pthread *) __hidden;
648 void	_thr_once_init(void) __hidden;
649 void	_thr_report_creation(struct pthread *curthread,
650 	    struct pthread *newthread) __hidden;
651 void	_thr_report_death(struct pthread *curthread) __hidden;
652 int	_thr_getscheduler(lwpid_t, int *, struct sched_param *) __hidden;
653 int	_thr_setscheduler(lwpid_t, int, const struct sched_param *) __hidden;
654 int	_rtp_to_schedparam(const struct rtprio *rtp, int *policy,
655 		struct sched_param *param) __hidden;
656 int	_schedparam_to_rtp(int policy, const struct sched_param *param,
657 		struct rtprio *rtp) __hidden;
658 void	_thread_bp_create(void);
659 void	_thread_bp_death(void);
660 int	_sched_yield(void);
661 
662 /* #include <fcntl.h> */
663 #ifdef  _SYS_FCNTL_H_
664 int     __sys_fcntl(int, int, ...);
665 int     __sys_open(const char *, int, ...);
666 #endif
667 
668 /* #include <signal.h> */
669 #ifdef _SIGNAL_H_
670 int	__sys_kill(pid_t, int);
671 int     __sys_sigaction(int, const struct sigaction *, struct sigaction *);
672 int     __sys_sigpending(sigset_t *);
673 int     __sys_sigprocmask(int, const sigset_t *, sigset_t *);
674 int     __sys_sigsuspend(const sigset_t *);
675 int     __sys_sigreturn(ucontext_t *);
676 int     __sys_sigaltstack(const struct sigaltstack *, struct sigaltstack *);
677 int	__sys_sigwait(const sigset_t *, int *);
678 int	__sys_sigtimedwait(const sigset_t *, siginfo_t *,
679 		const struct timespec *);
680 int	__sys_sigwaitinfo(const sigset_t *set, siginfo_t *info);
681 #endif
682 
683 /* #include <time.h> */
684 #ifdef	_TIME_H_
685 int	__sys_nanosleep(const struct timespec *, struct timespec *);
686 #endif
687 
688 /* #include <unistd.h> */
689 #ifdef  _UNISTD_H_
690 int     __sys_close(int);
691 int	__sys_fork(void);
692 pid_t	__sys_getpid(void);
693 ssize_t __sys_read(int, void *, size_t);
694 ssize_t __sys_write(int, const void *, size_t);
695 void	__sys_exit(int);
696 #endif
697 
698 static inline int
699 _thr_isthreaded(void)
700 {
701 	return (__isthreaded != 0);
702 }
703 
704 static inline int
705 _thr_is_inited(void)
706 {
707 	return (_thr_initial != NULL);
708 }
709 
710 static inline void
711 _thr_check_init(void)
712 {
713 	if (_thr_initial == NULL)
714 		_libpthread_init(NULL);
715 }
716 
717 __END_DECLS
718 
719 #endif  /* !_THR_PRIVATE_H */
720