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