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