2 * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by John Birrell.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * Private thread definitions for the uthread kernel.
34 * $Id: pthread_private.h,v 1.20 1999/06/20 08:28:08 jb Exp $
37 #ifndef _PTHREAD_PRIVATE_H
38 #define _PTHREAD_PRIVATE_H
41 * Evaluate the storage class specifier.
43 #ifdef GLOBAL_PTHREAD_PRIVATE
54 #include <sys/queue.h>
55 #include <sys/types.h>
59 #include <pthread_np.h>
62 * Kernel fatal error handler macro.
64 #define PANIC(string) _thread_exit(__FILE__,__LINE__,string)
66 /* Output debug messages like this: */
67 #define stdout_debug(_x) _thread_sys_write(1,_x,strlen(_x));
68 #define stderr_debug(_x) _thread_sys_write(2,_x,strlen(_x));
72 * Priority queue manipulation macros (using pqe link):
74 #define PTHREAD_PRIOQ_INSERT_HEAD(thrd) _pq_insert_head(&_readyq,thrd)
75 #define PTHREAD_PRIOQ_INSERT_TAIL(thrd) _pq_insert_tail(&_readyq,thrd)
76 #define PTHREAD_PRIOQ_REMOVE(thrd) _pq_remove(&_readyq,thrd)
77 #define PTHREAD_PRIOQ_FIRST() _pq_first(&_readyq)
80 * Waiting queue manipulation macros (using pqe link):
82 #if defined(_PTHREADS_INVARIANTS)
83 #define PTHREAD_WAITQ_REMOVE(thrd) _waitq_remove(thrd)
84 #define PTHREAD_WAITQ_INSERT(thrd) _waitq_insert(thrd)
85 #define PTHREAD_WAITQ_CLEARACTIVE() _waitq_clearactive()
86 #define PTHREAD_WAITQ_SETACTIVE() _waitq_setactive()
88 #define PTHREAD_WAITQ_REMOVE(thrd) TAILQ_REMOVE(&_waitingq,thrd,pqe)
89 #define PTHREAD_WAITQ_INSERT(thrd) do { \
90 if ((thrd)->wakeup_time.tv_sec == -1) \
91 TAILQ_INSERT_TAIL(&_waitingq,thrd,pqe); \
93 pthread_t tid = TAILQ_FIRST(&_waitingq); \
94 while ((tid != NULL) && (tid->wakeup_time.tv_sec != -1) && \
95 ((tid->wakeup_time.tv_sec < (thrd)->wakeup_time.tv_sec) || \
96 ((tid->wakeup_time.tv_sec == (thrd)->wakeup_time.tv_sec) && \
97 (tid->wakeup_time.tv_nsec <= (thrd)->wakeup_time.tv_nsec)))) \
98 tid = TAILQ_NEXT(tid, pqe); \
100 TAILQ_INSERT_TAIL(&_waitingq,thrd,pqe); \
102 TAILQ_INSERT_BEFORE(tid,thrd,pqe); \
105 #define PTHREAD_WAITQ_CLEARACTIVE()
106 #define PTHREAD_WAITQ_SETACTIVE()
110 * Work queue manipulation macros (using qe link):
112 #define PTHREAD_WORKQ_INSERT(thrd) do { \
113 TAILQ_INSERT_TAIL(&_workq,thrd,qe); \
114 (thrd)->flags |= PTHREAD_FLAGS_IN_WORKQ; \
116 #define PTHREAD_WORKQ_REMOVE(thrd) do { \
117 TAILQ_REMOVE(&_workq,thrd,qe); \
118 (thrd)->flags &= ~PTHREAD_FLAGS_IN_WORKQ; \
123 * State change macro without scheduling queue change:
125 #define PTHREAD_SET_STATE(thrd, newstate) do { \
126 (thrd)->state = newstate; \
127 (thrd)->fname = __FILE__; \
128 (thrd)->lineno = __LINE__; \
132 * State change macro with scheduling queue change - This must be
133 * called with preemption deferred (see thread_kern_sched_[un]defer).
135 #if defined(_PTHREADS_INVARIANTS)
136 #define PTHREAD_NEW_STATE(thrd, newstate) do { \
137 if (_thread_kern_new_state != 0) \
138 PANIC("Recursive PTHREAD_NEW_STATE"); \
139 _thread_kern_new_state = 1; \
140 if ((thrd)->state != newstate) { \
141 if ((thrd)->state == PS_RUNNING) { \
142 PTHREAD_PRIOQ_REMOVE(thrd); \
143 PTHREAD_WAITQ_INSERT(thrd); \
144 } else if (newstate == PS_RUNNING) { \
145 PTHREAD_WAITQ_REMOVE(thrd); \
146 PTHREAD_PRIOQ_INSERT_TAIL(thrd); \
149 _thread_kern_new_state = 0; \
150 PTHREAD_SET_STATE(thrd, newstate); \
153 #define PTHREAD_NEW_STATE(thrd, newstate) do { \
154 if ((thrd)->state != newstate) { \
155 if ((thrd)->state == PS_RUNNING) { \
156 PTHREAD_PRIOQ_REMOVE(thrd); \
157 PTHREAD_WAITQ_INSERT(thrd); \
158 } else if (newstate == PS_RUNNING) { \
159 PTHREAD_WAITQ_REMOVE(thrd); \
160 PTHREAD_PRIOQ_INSERT_TAIL(thrd); \
163 PTHREAD_SET_STATE(thrd, newstate); \
168 * Define the signals to be used for scheduling.
170 #if defined(_PTHREADS_COMPAT_SCHED)
171 #define _ITIMER_SCHED_TIMER ITIMER_VIRTUAL
172 #define _SCHED_SIGNAL SIGVTALRM
174 #define _ITIMER_SCHED_TIMER ITIMER_PROF
175 #define _SCHED_SIGNAL SIGPROF
181 * XXX It'd be nice if these were contained in uthread_priority_queue.[ch].
183 typedef struct pq_list {
184 TAILQ_HEAD(, pthread) pl_head; /* list of threads at this priority */
185 TAILQ_ENTRY(pq_list) pl_link; /* link for queue of priority lists */
186 int pl_prio; /* the priority of this list */
187 int pl_queued; /* is this in the priority queue */
190 typedef struct pq_queue {
191 TAILQ_HEAD(, pq_list) pq_queue; /* queue of priority lists */
192 pq_list_t *pq_lists; /* array of all priority lists */
193 int pq_size; /* number of priority lists */
198 * TailQ initialization values.
200 #define TAILQ_INITIALIZER { NULL, NULL }
205 union pthread_mutex_data {
210 struct pthread_mutex {
211 enum pthread_mutextype m_type;
213 TAILQ_HEAD(mutex_head, pthread) m_queue;
214 struct pthread *m_owner;
215 union pthread_mutex_data m_data;
220 * Used for priority inheritence and protection.
222 * m_prio - For priority inheritence, the highest active
223 * priority (threads locking the mutex inherit
224 * this priority). For priority protection, the
225 * ceiling priority of this mutex.
226 * m_saved_prio - mutex owners inherited priority before
227 * taking the mutex, restored when the owner
234 * Link for list of all mutexes a thread currently owns.
236 TAILQ_ENTRY(pthread_mutex) m_qe;
239 * Lock for accesses to this structure.
247 #define MUTEX_FLAGS_PRIVATE 0x01
248 #define MUTEX_FLAGS_INITED 0x02
249 #define MUTEX_FLAGS_BUSY 0x04
252 * Static mutex initialization values.
254 #define PTHREAD_MUTEX_STATIC_INITIALIZER \
255 { PTHREAD_MUTEX_DEFAULT, PTHREAD_PRIO_NONE, TAILQ_INITIALIZER, \
256 NULL, { NULL }, 0, 0, 0, 0, TAILQ_INITIALIZER, \
257 _SPINLOCK_INITIALIZER }
259 struct pthread_mutex_attr {
260 enum pthread_mutextype m_type;
267 * Condition variable definitions.
269 enum pthread_cond_type {
274 struct pthread_cond {
275 enum pthread_cond_type c_type;
276 TAILQ_HEAD(cond_head, pthread) c_queue;
277 pthread_mutex_t c_mutex;
282 * Lock for accesses to this structure.
287 struct pthread_cond_attr {
288 enum pthread_cond_type c_type;
293 * Flags for condition variables.
295 #define COND_FLAGS_PRIVATE 0x01
296 #define COND_FLAGS_INITED 0x02
297 #define COND_FLAGS_BUSY 0x04
300 * Static cond initialization values.
302 #define PTHREAD_COND_STATIC_INITIALIZER \
303 { COND_TYPE_FAST, TAILQ_INITIALIZER, NULL, NULL, \
304 0, _SPINLOCK_INITIALIZER }
307 * Cleanup definitions.
309 struct pthread_cleanup {
310 struct pthread_cleanup *next;
315 struct pthread_attr {
323 void (*cleanup_attr) ();
324 void *stackaddr_attr;
325 size_t stacksize_attr;
329 * Thread creation state attributes.
331 #define PTHREAD_CREATE_RUNNING 0
332 #define PTHREAD_CREATE_SUSPENDED 1
335 * Miscellaneous definitions.
337 #define PTHREAD_STACK_DEFAULT 65536
338 #ifdef _PTHREAD_GSTACK
339 /* Size of red zone at the end of each stack. */
340 #define PTHREAD_STACK_GUARD 4096
341 /* Maximum size of initial thread's stack. This perhaps deserves to be larger
342 * than the stacks of other threads, since legacy applications are likely to run
343 * almost entirely on this stack. */
344 #define PTHREAD_STACK_INITIAL 0x100000
345 /* Address immediately beyond the beginning of the initial thread stack. */
346 #if defined(__FreeBSD__)
347 # if defined(__alpha__)
348 # define PTHREAD_STACK_TOP 0x160022000
350 # define PTHREAD_STACK_TOP 0xbfbde000
353 # error "Don't recognize this operating system!"
356 #define PTHREAD_DEFAULT_PRIORITY 64
357 #define PTHREAD_MAX_PRIORITY 126
358 #define PTHREAD_MIN_PRIORITY 0
359 #define _POSIX_THREAD_ATTR_STACKSIZE
362 * Clock resolution in nanoseconds.
364 #define CLOCK_RES_NSEC 10000000
367 * Time slice period in microseconds.
369 #define TIMESLICE_USEC 100000
373 volatile int allocated;
375 void (*destructor) ();
378 struct pthread_rwlockattr {
382 struct pthread_rwlock {
383 pthread_mutex_t lock; /* monitor lock */
384 int state; /* 0 = idle >0 = # of readers -1 = writer */
385 pthread_cond_t read_signal;
386 pthread_cond_t write_signal;
419 * File descriptor locking definitions.
423 #define FD_RDWR (FD_READ | FD_WRITE)
426 * File descriptor table structure.
428 struct fd_table_entry {
430 * Lock for accesses to this file descriptor table
431 * entry. This is passed to _spinlock() to provide atomic
432 * access to this structure. It does *not* represent the
433 * state of the lock on the file descriptor.
436 TAILQ_HEAD(, pthread) r_queue; /* Read queue. */
437 TAILQ_HEAD(, pthread) w_queue; /* Write queue. */
438 struct pthread *r_owner; /* Ptr to thread owning read lock. */
439 struct pthread *w_owner; /* Ptr to thread owning write lock. */
440 char *r_fname; /* Ptr to read lock source file name */
441 int r_lineno; /* Read lock source line number. */
442 char *w_fname; /* Ptr to write lock source file name */
443 int w_lineno; /* Write lock source line number. */
444 int r_lockcount; /* Count for FILE read locks. */
445 int w_lockcount; /* Count for FILE write locks. */
446 int flags; /* Flags used in open. */
449 struct pthread_poll_data {
454 union pthread_wait_data {
455 pthread_mutex_t mutex;
457 const sigset_t *sigwait; /* Waiting on a signal in sigwait */
459 short fd; /* Used when thread waiting on fd */
460 short branch; /* Line number, for debugging. */
461 char *fname; /* Source file name for debugging.*/
463 struct pthread_poll_data * poll_data;
464 spinlock_t *spinlock;
472 * Magic value to help recognize a valid thread structure
473 * from an invalid one:
475 #define PTHREAD_MAGIC ((u_int32_t) 0xd09ba115)
480 * Lock for accesses to this thread structure.
484 /* Queue entry for list of all threads: */
485 TAILQ_ENTRY(pthread) tle;
487 /* Queue entry for list of dead threads: */
488 TAILQ_ENTRY(pthread) dle;
491 * Thread start routine, argument, stack pointer and thread
494 void *(*start_routine)(void *);
497 struct pthread_attr attr;
499 #if (defined(__FreeBSD__) || defined(__NetBSD__)) && defined(__i386__)
501 * Saved floating point registers on systems where they are not
502 * saved in the signal context.
508 * Saved signal context used in call to sigreturn by
509 * _thread_kern_sched if sig_saved is TRUE.
511 struct sigcontext saved_sigcontext;
514 * Saved jump buffer used in call to longjmp by _thread_kern_sched
515 * if sig_saved is FALSE.
517 jmp_buf saved_jmp_buf;
520 * TRUE if the last state saved was a signal context. FALSE if the
521 * last state saved was a jump buffer.
526 * Current signal mask and pending signals.
532 enum pthread_state state;
534 /* Time that this thread was last made active. */
535 struct timeval last_active;
537 /* Time that this thread was last made inactive. */
538 struct timeval last_inactive;
541 * Number of microseconds accumulated by this thread when
542 * time slicing is active.
547 * Incremental priority accumulated by thread while it is ready to
548 * run but is denied being run.
553 * Time to wake up thread. This is used for sleeping threads and
554 * for any operation which may time out (such as select).
556 struct timespec wakeup_time;
558 /* TRUE if operation has timed out. */
562 * Error variable used instead of errno. The function __error()
563 * returns a pointer to this.
567 /* Join queue head and link for waiting threads: */
568 TAILQ_HEAD(join_head, pthread) join_queue;
571 * The current thread can belong to only one scheduling queue at
572 * a time (ready or waiting queue). It can also belong to (only)
575 * o A queue of threads waiting for a mutex
576 * o A queue of threads waiting for a condition variable
577 * o A queue of threads waiting for another thread to terminate
578 * (the join queue above)
579 * o A queue of threads waiting for a file descriptor lock
580 * o A queue of threads needing work done by the kernel thread
581 * (waiting for a spinlock or file I/O)
583 * Use pqe for the scheduling queue link (both ready and waiting),
584 * and qe for other links.
587 /* Priority queue entry for this thread: */
588 TAILQ_ENTRY(pthread) pqe;
590 /* Queue entry for this thread: */
591 TAILQ_ENTRY(pthread) qe;
594 union pthread_wait_data data;
597 * Allocated for converting select into poll.
599 struct pthread_poll_data poll_data;
602 * Set to TRUE if a blocking operation was
603 * interrupted by a signal:
607 /* Signal number when in state PS_SIGWAIT: */
611 * Set to non-zero when this thread has deferred signals.
612 * We allow for recursive deferral.
617 * Set to TRUE if this thread should yield after undeferring
620 int yield_on_sig_undefer;
622 /* Miscellaneous data. */
624 #define PTHREAD_FLAGS_PRIVATE 0x0001
625 #define PTHREAD_EXITING 0x0002
626 #define PTHREAD_FLAGS_IN_CONDQ 0x0004 /* in condition queue using qe link*/
627 #define PTHREAD_FLAGS_IN_WORKQ 0x0008 /* in work queue using qe link */
628 #define PTHREAD_FLAGS_IN_WAITQ 0x0010 /* in waiting queue using pqe link*/
629 #define PTHREAD_FLAGS_IN_PRIOQ 0x0020 /* in priority queue using pqe link*/
630 #define PTHREAD_FLAGS_TRACE 0x0040 /* for debugging purposes */
633 * Base priority is the user setable and retrievable priority
634 * of the thread. It is only affected by explicit calls to
635 * set thread priority and upon thread creation via a thread
636 * attribute or default priority.
641 * Inherited priority is the priority a thread inherits by
642 * taking a priority inheritence or protection mutex. It
643 * is not affected by base priority changes. Inherited
644 * priority defaults to and remains 0 until a mutex is taken
645 * that is being waited on by any other thread whose priority
648 char inherited_priority;
651 * Active priority is always the maximum of the threads base
652 * priority and inherited priority. When there is a change
653 * in either the base or inherited priority, the active
654 * priority must be recalculated.
656 char active_priority;
658 /* Number of priority ceiling or protection mutexes owned. */
659 int priority_mutex_count;
662 * Queue of currently owned mutexes.
664 TAILQ_HEAD(, pthread_mutex) mutexq;
667 const void **specific_data;
668 int specific_data_count;
670 /* Cleanup handlers Link List */
671 struct pthread_cleanup *cleanup;
672 char *fname; /* Ptr to source file name */
673 int lineno; /* Source line number. */
676 #ifdef _PTHREAD_GSTACK
677 /* Spare thread stack. */
679 SLIST_ENTRY(stack) qe; /* Queue entry for this stack. */
684 * Global variables for the uthread kernel.
687 /* Kernel thread structure used when there are no running threads: */
688 SCLASS struct pthread _thread_kern_thread;
690 /* Ptr to the thread structure for the running thread: */
691 SCLASS struct pthread * volatile _thread_run
692 #ifdef GLOBAL_PTHREAD_PRIVATE
693 = &_thread_kern_thread;
698 /* Ptr to the thread structure for the last user thread to run: */
699 SCLASS struct pthread * volatile _last_user_thread
700 #ifdef GLOBAL_PTHREAD_PRIVATE
701 = &_thread_kern_thread;
707 * Ptr to the thread running in single-threaded mode or NULL if
708 * running multi-threaded (default POSIX behaviour).
710 SCLASS struct pthread * volatile _thread_single
711 #ifdef GLOBAL_PTHREAD_PRIVATE
717 /* List of all threads: */
718 SCLASS TAILQ_HEAD(, pthread) _thread_list
719 #ifdef GLOBAL_PTHREAD_PRIVATE
720 = TAILQ_HEAD_INITIALIZER(_thread_list);
726 * Array of kernel pipe file descriptors that are used to ensure that
727 * no signals are missed in calls to _select.
729 SCLASS int _thread_kern_pipe[2]
730 #ifdef GLOBAL_PTHREAD_PRIVATE
738 SCLASS int volatile _queue_signals
739 #ifdef GLOBAL_PTHREAD_PRIVATE
744 SCLASS int _thread_kern_in_sched
745 #ifdef GLOBAL_PTHREAD_PRIVATE
751 /* Last time that an incremental priority update was performed: */
752 SCLASS struct timeval kern_inc_prio_time
753 #ifdef GLOBAL_PTHREAD_PRIVATE
760 SCLASS TAILQ_HEAD(, pthread) _dead_list
761 #ifdef GLOBAL_PTHREAD_PRIVATE
762 = TAILQ_HEAD_INITIALIZER(_dead_list);
767 /* Initial thread: */
768 SCLASS struct pthread *_thread_initial
769 #ifdef GLOBAL_PTHREAD_PRIVATE
775 /* Default thread attributes: */
776 SCLASS struct pthread_attr pthread_attr_default
777 #ifdef GLOBAL_PTHREAD_PRIVATE
778 = { SCHED_RR, 0, TIMESLICE_USEC, PTHREAD_DEFAULT_PRIORITY, PTHREAD_CREATE_RUNNING,
779 PTHREAD_CREATE_JOINABLE, NULL, NULL, NULL, PTHREAD_STACK_DEFAULT };
784 /* Default mutex attributes: */
785 SCLASS struct pthread_mutex_attr pthread_mutexattr_default
786 #ifdef GLOBAL_PTHREAD_PRIVATE
787 = { PTHREAD_MUTEX_DEFAULT, PTHREAD_PRIO_NONE, 0, 0 };
792 /* Default condition variable attributes: */
793 SCLASS struct pthread_cond_attr pthread_condattr_default
794 #ifdef GLOBAL_PTHREAD_PRIVATE
795 = { COND_TYPE_FAST, 0 };
801 * Standard I/O file descriptors need special flag treatment since
802 * setting one to non-blocking does all on *BSD. Sigh. This array
803 * is used to store the initial flag settings.
805 SCLASS int _pthread_stdio_flags[3];
807 /* File table information: */
808 SCLASS struct fd_table_entry **_thread_fd_table
809 #ifdef GLOBAL_PTHREAD_PRIVATE
815 /* Table for polling file descriptors: */
816 SCLASS struct pollfd *_thread_pfd_table
817 #ifdef GLOBAL_PTHREAD_PRIVATE
823 SCLASS const int dtablecount
824 #ifdef GLOBAL_PTHREAD_PRIVATE
825 = 4096/sizeof(struct fd_table_entry);
829 SCLASS int _thread_dtablesize /* Descriptor table size. */
830 #ifdef GLOBAL_PTHREAD_PRIVATE
836 SCLASS int _clock_res_nsec /* Clock resolution in nsec. */
837 #ifdef GLOBAL_PTHREAD_PRIVATE
843 /* Garbage collector mutex and condition variable. */
844 SCLASS pthread_mutex_t _gc_mutex
845 #ifdef GLOBAL_PTHREAD_PRIVATE
849 SCLASS pthread_cond_t _gc_cond
850 #ifdef GLOBAL_PTHREAD_PRIVATE
856 * Array of signal actions for this process.
858 struct sigaction _thread_sigact[NSIG];
863 SCLASS pq_queue_t _readyq;
864 SCLASS TAILQ_HEAD(, pthread) _waitingq;
869 SCLASS TAILQ_HEAD(, pthread) _workq;
871 /* Tracks the number of threads blocked while waiting for a spinlock. */
872 SCLASS volatile int _spinblock_count
873 #ifdef GLOBAL_PTHREAD_PRIVATE
878 /* Indicates that the signal queue needs to be checked. */
879 SCLASS volatile int _sigq_check_reqd
880 #ifdef GLOBAL_PTHREAD_PRIVATE
885 /* Thread switch hook. */
886 SCLASS pthread_switch_routine_t _sched_switch_hook
887 #ifdef GLOBAL_PTHREAD_PRIVATE
892 #ifdef _PTHREAD_GSTACK
893 /* Spare stack queue. Stacks of default size are cached in order to reduce
894 * thread creation time. Spare stacks are used in LIFO order to increase cache
896 SCLASS SLIST_HEAD(, stack) _stackq;
898 /* Base address of next unallocated default-size stack. Stacks are allocated
899 * contiguously, starting below the beginning of the main stack. When a new
900 * stack is created, a guard page is created just above it in order to (usually)
901 * detect attempts by the adjacent stack to trounce the next thread stack. */
902 SCLASS void * _next_stack
903 #ifdef GLOBAL_PTHREAD_PRIVATE
904 /* main stack top - main stack size - stack size - (red zone + main stack red zone) */
905 = (void *) PTHREAD_STACK_TOP - PTHREAD_STACK_INITIAL - PTHREAD_STACK_DEFAULT - (2 * PTHREAD_STACK_GUARD)
910 /* Used for _PTHREADS_INVARIANTS checking. */
911 SCLASS int _thread_kern_new_state
912 #ifdef GLOBAL_PTHREAD_PRIVATE
917 /* Undefine the storage class specifier: */
921 #define _FD_LOCK(_fd,_type,_ts) _thread_fd_lock_debug(_fd, _type, \
922 _ts, __FILE__, __LINE__)
923 #define _FD_UNLOCK(_fd,_type) _thread_fd_unlock_debug(_fd, _type, \
926 #define _FD_LOCK(_fd,_type,_ts) _thread_fd_lock(_fd, _type, _ts)
927 #define _FD_UNLOCK(_fd,_type) _thread_fd_unlock(_fd, _type)
931 * Function prototype definitions.
934 char *__ttyname_basic(int);
935 char *__ttyname_r_basic(int, char *, size_t);
936 char *ttyname_r(int, char *, size_t);
937 int _find_dead_thread(pthread_t);
938 int _find_thread(pthread_t);
939 int _thread_create(pthread_t *,const pthread_attr_t *,void *(*start_routine)(void *),void *,pthread_t);
940 int _thread_fd_lock(int, int, struct timespec *);
941 int _thread_fd_lock_debug(int, int, struct timespec *,char *fname,int lineno);
942 void _dispatch_signals(void);
943 void _thread_signal(pthread_t, int);
944 int _mutex_cv_lock(pthread_mutex_t *);
945 int _mutex_cv_unlock(pthread_mutex_t *);
946 int _mutex_reinit(pthread_mutex_t *);
947 void _mutex_notify_priochange(struct pthread *);
948 int _cond_reinit(pthread_cond_t *);
949 int _pq_alloc(struct pq_queue *, int, int);
950 int _pq_init(struct pq_queue *);
951 void _pq_remove(struct pq_queue *pq, struct pthread *);
952 void _pq_insert_head(struct pq_queue *pq, struct pthread *);
953 void _pq_insert_tail(struct pq_queue *pq, struct pthread *);
954 struct pthread *_pq_first(struct pq_queue *pq);
955 #if defined(_PTHREADS_INVARIANTS)
956 void _waitq_insert(pthread_t pthread);
957 void _waitq_remove(pthread_t pthread);
958 void _waitq_setactive(void);
959 void _waitq_clearactive(void);
961 void _thread_exit(char *, int, char *);
962 void _thread_fd_unlock(int, int);
963 void _thread_fd_unlock_debug(int, int, char *, int);
964 void *_thread_cleanup(pthread_t);
965 void _thread_cleanupspecific(void);
966 void _thread_dump_info(void);
967 void _thread_init(void);
968 void _thread_kern_sched(struct sigcontext *);
969 void _thread_kern_sched_state(enum pthread_state,char *fname,int lineno);
970 void _thread_kern_sched_state_unlock(enum pthread_state state,
971 spinlock_t *lock, char *fname, int lineno);
972 void _thread_kern_set_timeout(struct timespec *);
973 void _thread_kern_sig_defer(void);
974 void _thread_kern_sig_undefer(void);
975 void _thread_sig_handler(int, int, struct sigcontext *);
976 void _thread_sig_handle(int, struct sigcontext *);
977 void _thread_sig_init(void);
978 void _thread_start(void);
979 void _thread_start_sig_handler(void);
980 void _thread_seterrno(pthread_t,int);
981 int _thread_fd_table_init(int fd);
982 pthread_addr_t _thread_gc(pthread_addr_t);
984 /* #include <signal.h> */
985 int _thread_sys_sigaction(int, const struct sigaction *, struct sigaction *);
986 int _thread_sys_sigpending(sigset_t *);
987 int _thread_sys_sigprocmask(int, const sigset_t *, sigset_t *);
988 int _thread_sys_sigsuspend(const sigset_t *);
989 int _thread_sys_siginterrupt(int, int);
990 int _thread_sys_sigpause(int);
991 int _thread_sys_sigreturn(struct sigcontext *);
992 int _thread_sys_sigstack(const struct sigstack *, struct sigstack *);
993 int _thread_sys_sigvec(int, struct sigvec *, struct sigvec *);
994 void _thread_sys_psignal(unsigned int, const char *);
995 void (*_thread_sys_signal(int, void (*)(int)))(int);
997 /* #include <sys/stat.h> */
999 int _thread_sys_fchmod(int, mode_t);
1000 int _thread_sys_fstat(int, struct stat *);
1001 int _thread_sys_fchflags(int, u_long);
1004 /* #include <sys/mount.h> */
1005 #ifdef _SYS_MOUNT_H_
1006 int _thread_sys_fstatfs(int, struct statfs *);
1008 int _thread_sys_pipe(int *);
1010 /* #include <sys/socket.h> */
1011 #ifdef _SYS_SOCKET_H_
1012 int _thread_sys_accept(int, struct sockaddr *, int *);
1013 int _thread_sys_bind(int, const struct sockaddr *, int);
1014 int _thread_sys_connect(int, const struct sockaddr *, int);
1015 int _thread_sys_getpeername(int, struct sockaddr *, int *);
1016 int _thread_sys_getsockname(int, struct sockaddr *, int *);
1017 int _thread_sys_getsockopt(int, int, int, void *, int *);
1018 int _thread_sys_listen(int, int);
1019 int _thread_sys_setsockopt(int, int, int, const void *, int);
1020 int _thread_sys_shutdown(int, int);
1021 int _thread_sys_socket(int, int, int);
1022 int _thread_sys_socketpair(int, int, int, int *);
1023 ssize_t _thread_sys_recv(int, void *, size_t, int);
1024 ssize_t _thread_sys_recvfrom(int, void *, size_t, int, struct sockaddr *, int *);
1025 ssize_t _thread_sys_recvmsg(int, struct msghdr *, int);
1026 ssize_t _thread_sys_send(int, const void *, size_t, int);
1027 ssize_t _thread_sys_sendmsg(int, const struct msghdr *, int);
1028 ssize_t _thread_sys_sendto(int, const void *,size_t, int, const struct sockaddr *, int);
1031 /* #include <stdio.h> */
1033 FILE *_thread_sys_fdopen(int, const char *);
1034 FILE *_thread_sys_fopen(const char *, const char *);
1035 FILE *_thread_sys_freopen(const char *, const char *, FILE *);
1036 FILE *_thread_sys_popen(const char *, const char *);
1037 FILE *_thread_sys_tmpfile(void);
1038 char *_thread_sys_ctermid(char *);
1039 char *_thread_sys_cuserid(char *);
1040 char *_thread_sys_fgetln(FILE *, size_t *);
1041 char *_thread_sys_fgets(char *, int, FILE *);
1042 char *_thread_sys_gets(char *);
1043 char *_thread_sys_tempnam(const char *, const char *);
1044 char *_thread_sys_tmpnam(char *);
1045 int _thread_sys_fclose(FILE *);
1046 int _thread_sys_feof(FILE *);
1047 int _thread_sys_ferror(FILE *);
1048 int _thread_sys_fflush(FILE *);
1049 int _thread_sys_fgetc(FILE *);
1050 int _thread_sys_fgetpos(FILE *, fpos_t *);
1051 int _thread_sys_fileno(FILE *);
1052 int _thread_sys_fprintf(FILE *, const char *, ...);
1053 int _thread_sys_fpurge(FILE *);
1054 int _thread_sys_fputc(int, FILE *);
1055 int _thread_sys_fputs(const char *, FILE *);
1056 int _thread_sys_fscanf(FILE *, const char *, ...);
1057 int _thread_sys_fseek(FILE *, long, int);
1058 int _thread_sys_fsetpos(FILE *, const fpos_t *);
1059 int _thread_sys_getc(FILE *);
1060 int _thread_sys_getchar(void);
1061 int _thread_sys_getw(FILE *);
1062 int _thread_sys_pclose(FILE *);
1063 int _thread_sys_printf(const char *, ...);
1064 int _thread_sys_putc(int, FILE *);
1065 int _thread_sys_putchar(int);
1066 int _thread_sys_puts(const char *);
1067 int _thread_sys_putw(int, FILE *);
1068 int _thread_sys_remove(const char *);
1069 int _thread_sys_rename (const char *, const char *);
1070 int _thread_sys_scanf(const char *, ...);
1071 int _thread_sys_setlinebuf(FILE *);
1072 int _thread_sys_setvbuf(FILE *, char *, int, size_t);
1073 int _thread_sys_snprintf(char *, size_t, const char *, ...);
1074 int _thread_sys_sprintf(char *, const char *, ...);
1075 int _thread_sys_sscanf(const char *, const char *, ...);
1076 int _thread_sys_ungetc(int, FILE *);
1077 int _thread_sys_vfprintf(FILE *, const char *, _BSD_VA_LIST_);
1078 int _thread_sys_vprintf(const char *, _BSD_VA_LIST_);
1079 int _thread_sys_vscanf(const char *, _BSD_VA_LIST_);
1080 int _thread_sys_vsnprintf(char *, size_t, const char *, _BSD_VA_LIST_);
1081 int _thread_sys_vsprintf(char *, const char *, _BSD_VA_LIST_);
1082 int _thread_sys_vsscanf(const char *, const char *, _BSD_VA_LIST_);
1083 long _thread_sys_ftell(FILE *);
1084 size_t _thread_sys_fread(void *, size_t, size_t, FILE *);
1085 size_t _thread_sys_fwrite(const void *, size_t, size_t, FILE *);
1086 void _thread_sys_clearerr(FILE *);
1087 void _thread_sys_perror(const char *);
1088 void _thread_sys_rewind(FILE *);
1089 void _thread_sys_setbuf(FILE *, char *);
1090 void _thread_sys_setbuffer(FILE *, char *, int);
1093 /* #include <unistd.h> */
1095 char *_thread_sys_ttyname(int);
1096 int _thread_sys_close(int);
1097 int _thread_sys_dup(int);
1098 int _thread_sys_dup2(int, int);
1099 int _thread_sys_exect(const char *, char * const *, char * const *);
1100 int _thread_sys_execve(const char *, char * const *, char * const *);
1101 int _thread_sys_fchdir(int);
1102 int _thread_sys_fchown(int, uid_t, gid_t);
1103 int _thread_sys_fsync(int);
1104 int _thread_sys_ftruncate(int, off_t);
1105 int _thread_sys_pause(void);
1106 int _thread_sys_pipe(int *);
1107 int _thread_sys_select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
1108 off_t _thread_sys_lseek(int, off_t, int);
1109 pid_t _thread_sys_fork(void);
1110 pid_t _thread_sys_tcgetpgrp(int);
1111 ssize_t _thread_sys_read(int, void *, size_t);
1112 ssize_t _thread_sys_write(int, const void *, size_t);
1113 void _thread_sys__exit(int);
1116 /* #include <fcntl.h> */
1117 #ifdef _SYS_FCNTL_H_
1118 int _thread_sys_creat(const char *, mode_t);
1119 int _thread_sys_fcntl(int, int, ...);
1120 int _thread_sys_flock(int, int);
1121 int _thread_sys_open(const char *, int, ...);
1124 /* #include <sys/ioctl.h> */
1125 #ifdef _SYS_IOCTL_H_
1126 int _thread_sys_ioctl(int, unsigned long, ...);
1129 /* #include <dirent.h> */
1131 DIR *___thread_sys_opendir2(const char *, int);
1132 DIR *_thread_sys_opendir(const char *);
1133 int _thread_sys_alphasort(const void *, const void *);
1134 int _thread_sys_scandir(const char *, struct dirent ***,
1135 int (*)(struct dirent *), int (*)(const void *, const void *));
1136 int _thread_sys_closedir(DIR *);
1137 int _thread_sys_getdirentries(int, char *, int, long *);
1138 long _thread_sys_telldir(const DIR *);
1139 struct dirent *_thread_sys_readdir(DIR *);
1140 void _thread_sys_rewinddir(DIR *);
1141 void _thread_sys_seekdir(DIR *, long);
1144 /* #include <sys/uio.h> */
1146 ssize_t _thread_sys_readv(int, const struct iovec *, int);
1147 ssize_t _thread_sys_writev(int, const struct iovec *, int);
1150 /* #include <sys/wait.h> */
1152 pid_t _thread_sys_wait(int *);
1153 pid_t _thread_sys_waitpid(pid_t, int *, int);
1154 pid_t _thread_sys_wait3(int *, int, struct rusage *);
1155 pid_t _thread_sys_wait4(pid_t, int *, int, struct rusage *);
1158 /* #include <poll.h> */
1160 int _thread_sys_poll(struct pollfd *, unsigned, int);
1164 #endif /* !_PTHREAD_PRIVATE_H */