1996-01-22 00:23:58 +00:00
|
|
|
/*
|
1998-04-03 09:31:15 +00:00
|
|
|
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>.
|
1996-01-22 00:23:58 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by John Birrell.
|
|
|
|
* 4. Neither the name of the author nor the names of any co-contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
1999-08-05 12:08:10 +00:00
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
1996-01-22 00:23:58 +00:00
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* Private thread definitions for the uthread kernel.
|
|
|
|
*
|
1999-08-28 00:22:10 +00:00
|
|
|
* $FreeBSD$
|
1996-01-22 00:23:58 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _PTHREAD_PRIVATE_H
|
|
|
|
#define _PTHREAD_PRIVATE_H
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Evaluate the storage class specifier.
|
|
|
|
*/
|
|
|
|
#ifdef GLOBAL_PTHREAD_PRIVATE
|
|
|
|
#define SCLASS
|
|
|
|
#else
|
|
|
|
#define SCLASS extern
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Include files.
|
|
|
|
*/
|
|
|
|
#include <setjmp.h>
|
|
|
|
#include <signal.h>
|
2000-10-13 22:12:32 +00:00
|
|
|
#include <stdio.h>
|
1998-04-11 07:47:22 +00:00
|
|
|
#include <sys/queue.h>
|
1996-01-22 00:23:58 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/time.h>
|
2000-03-18 22:36:46 +00:00
|
|
|
#include <sys/cdefs.h>
|
1998-03-08 02:37:27 +00:00
|
|
|
#include <sched.h>
|
1998-06-09 23:02:43 +00:00
|
|
|
#include <spinlock.h>
|
2002-02-17 17:21:27 +00:00
|
|
|
#include <ucontext.h>
|
1999-03-23 05:07:56 +00:00
|
|
|
#include <pthread_np.h>
|
1996-01-22 00:23:58 +00:00
|
|
|
|
2000-10-13 22:12:32 +00:00
|
|
|
/*
|
|
|
|
* Define machine dependent macros to get and set the stack pointer
|
|
|
|
* from the supported contexts. Also define a macro to set the return
|
|
|
|
* address in a jmp_buf context.
|
|
|
|
*
|
|
|
|
* XXX - These need to be moved into architecture dependent support files.
|
2003-01-05 22:37:03 +00:00
|
|
|
* XXX - These need to be documented so porters know what's required.
|
2000-10-13 22:12:32 +00:00
|
|
|
*/
|
|
|
|
#if defined(__i386__)
|
|
|
|
#define GET_STACK_JB(jb) ((unsigned long)((jb)[0]._jb[2]))
|
|
|
|
#define GET_STACK_SJB(sjb) ((unsigned long)((sjb)[0]._sjb[2]))
|
|
|
|
#define GET_STACK_UC(ucp) ((unsigned long)((ucp)->uc_mcontext.mc_esp))
|
|
|
|
#define SET_STACK_JB(jb, stk) (jb)[0]._jb[2] = (int)(stk)
|
|
|
|
#define SET_STACK_SJB(sjb, stk) (sjb)[0]._sjb[2] = (int)(stk)
|
|
|
|
#define SET_STACK_UC(ucp, stk) (ucp)->uc_mcontext.mc_esp = (int)(stk)
|
|
|
|
#define FP_SAVE_UC(ucp) do { \
|
|
|
|
char *fdata; \
|
2002-09-30 08:45:38 +00:00
|
|
|
fdata = (char *) (ucp)->uc_mcontext.mc_fpstate; \
|
2000-10-13 22:12:32 +00:00
|
|
|
__asm__("fnsave %0": :"m"(*fdata)); \
|
|
|
|
} while (0)
|
|
|
|
#define FP_RESTORE_UC(ucp) do { \
|
|
|
|
char *fdata; \
|
2002-09-30 08:45:38 +00:00
|
|
|
fdata = (char *) (ucp)->uc_mcontext.mc_fpstate; \
|
2000-10-13 22:12:32 +00:00
|
|
|
__asm__("frstor %0": :"m"(*fdata)); \
|
|
|
|
} while (0)
|
2004-01-22 19:15:08 +00:00
|
|
|
#define SET_RETURN_ADDR_JB(jb, ra) do { \
|
|
|
|
(jb)[0]._jb[0] = (int)(ra); \
|
|
|
|
(jb)[0]._jb[3] = 0; \
|
|
|
|
} while (0)
|
2003-06-02 22:22:52 +00:00
|
|
|
#elif defined(__amd64__)
|
|
|
|
#define GET_STACK_JB(jb) ((unsigned long)((jb)[0]._jb[2]))
|
|
|
|
#define GET_STACK_SJB(sjb) ((unsigned long)((sjb)[0]._sjb[2]))
|
|
|
|
#define GET_STACK_UC(ucp) ((unsigned long)((ucp)->uc_mcontext.mc_rsp))
|
|
|
|
#define SET_STACK_JB(jb, stk) (jb)[0]._jb[2] = (long)(stk)
|
|
|
|
#define SET_STACK_SJB(sjb, stk) (sjb)[0]._sjb[2] = (long)(stk)
|
|
|
|
#define SET_STACK_UC(ucp, stk) (ucp)->uc_mcontext.mc_rsp = (long)(stk)
|
|
|
|
#define FP_SAVE_UC(ucp) do { \
|
|
|
|
char *fdata; \
|
|
|
|
fdata = (char *) (ucp)->uc_mcontext.mc_fpstate; \
|
|
|
|
__asm__("fxsave %0": :"m"(*fdata)); \
|
|
|
|
} while (0)
|
|
|
|
#define FP_RESTORE_UC(ucp) do { \
|
|
|
|
char *fdata; \
|
|
|
|
fdata = (char *) (ucp)->uc_mcontext.mc_fpstate; \
|
|
|
|
__asm__("fxrstor %0": :"m"(*fdata)); \
|
|
|
|
} while (0)
|
|
|
|
#define SET_RETURN_ADDR_JB(jb, ra) (jb)[0]._jb[0] = (long)(ra)
|
2000-10-13 22:12:32 +00:00
|
|
|
#elif defined(__alpha__)
|
|
|
|
#include <machine/reg.h>
|
2000-10-17 06:31:40 +00:00
|
|
|
#define GET_STACK_JB(jb) ((unsigned long)((jb)[0]._jb[R_SP + 4]))
|
|
|
|
#define GET_STACK_SJB(sjb) ((unsigned long)((sjb)[0]._sjb[R_SP + 4]))
|
|
|
|
#define GET_STACK_UC(ucp) ((ucp)->uc_mcontext.mc_regs[R_SP])
|
2000-10-13 22:12:32 +00:00
|
|
|
#define SET_STACK_JB(jb, stk) (jb)[0]._jb[R_SP + 4] = (long)(stk)
|
|
|
|
#define SET_STACK_SJB(sjb, stk) (sjb)[0]._sjb[R_SP + 4] = (long)(stk)
|
|
|
|
#define SET_STACK_UC(ucp, stk) (ucp)->uc_mcontext.mc_regs[R_SP] = (unsigned long)(stk)
|
|
|
|
#define FP_SAVE_UC(ucp)
|
|
|
|
#define FP_RESTORE_UC(ucp)
|
2000-11-20 01:57:19 +00:00
|
|
|
#define SET_RETURN_ADDR_JB(jb, ra) do { \
|
2001-12-22 06:11:06 +00:00
|
|
|
(jb)[0]._jb[2] = (long)(ra); \
|
|
|
|
(jb)[0]._jb[R_RA + 4] = (long)(ra); \
|
2000-11-20 01:57:19 +00:00
|
|
|
(jb)[0]._jb[R_T12 + 4] = (long)(ra); \
|
2000-10-13 22:12:32 +00:00
|
|
|
} while (0)
|
2003-01-06 00:56:23 +00:00
|
|
|
#elif defined(__ia64__)
|
|
|
|
#define GET_BSP_JB(jb) (*((unsigned long*)JMPBUF_ADDR_OF(jb,J_BSP)))
|
|
|
|
#define GET_STACK_JB(jb) (*((unsigned long*)JMPBUF_ADDR_OF(jb,J_SP)))
|
|
|
|
#define GET_STACK_SJB(sjb) GET_STACK_JB(sjb)
|
|
|
|
#define SET_RETURN_ADDR_JB(jb, ra) \
|
|
|
|
do { \
|
|
|
|
*((unsigned long*)JMPBUF_ADDR_OF(jb,J_B0)) = ((long*)(ra))[0]; \
|
2003-03-05 04:39:24 +00:00
|
|
|
*((unsigned long*)JMPBUF_ADDR_OF(jb,J_GP)) = ((long*)(ra))[1]; \
|
2003-01-06 00:56:23 +00:00
|
|
|
*((unsigned long*)JMPBUF_ADDR_OF(jb,J_PFS)) &= ~0x1FFFFFFFFFUL; \
|
|
|
|
} while (0)
|
|
|
|
#define SET_STACK_JB(jb, stk, sz) \
|
|
|
|
do { \
|
|
|
|
UPD_STACK_JB(jb, stk + sz - 16); \
|
|
|
|
GET_BSP_JB(jb) = (long)(stk); \
|
|
|
|
} while (0)
|
|
|
|
#define UPD_STACK_JB(jb, stk) GET_STACK_JB(jb) = (long)(stk)
|
2003-01-05 22:37:03 +00:00
|
|
|
#elif defined(__sparc64__)
|
|
|
|
#include <machine/frame.h>
|
|
|
|
|
|
|
|
#define CCFSZ sizeof (struct frame)
|
|
|
|
|
|
|
|
#define GET_STACK_JB(jb) \
|
|
|
|
((unsigned long)((jb)[0]._jb[_JB_SP]) + SPOFF)
|
|
|
|
#define GET_STACK_SJB(sjb) \
|
|
|
|
((unsigned long)((sjb)[0]._sjb[_JB_SP]) + SPOFF)
|
|
|
|
#define GET_STACK_UC(ucp) \
|
|
|
|
((ucp)->uc_mcontext.mc_sp + SPOFF)
|
|
|
|
/*
|
|
|
|
* XXX: sparc64 _longjmp() expects a register window on the stack
|
|
|
|
* at the given position, so we must make sure that the space where
|
|
|
|
* it is expected is readable. Subtracting the frame size here works
|
|
|
|
* because the SET_STACK macros are only used to set up new stacks
|
|
|
|
* or signal stacks, but it is a bit dirty.
|
|
|
|
*/
|
|
|
|
#define SET_STACK_JB(jb, stk) \
|
|
|
|
(jb)[0]._jb[_JB_SP] = (long)(stk) - SPOFF - CCFSZ
|
|
|
|
#define SET_STACK_SJB(sjb, stk) \
|
|
|
|
(sjb)[0]._sjb[_JB_SP] = (long)(stk) - SPOFF - CCFSZ
|
|
|
|
#define SET_STACK_UC(ucp, stk) \
|
|
|
|
(ucp)->uc_mcontext.mc_sp = (unsigned long)(stk) - SPOFF - CCFSZ
|
|
|
|
#define FP_SAVE_UC(ucp) /* XXX */
|
|
|
|
#define FP_RESTORE_UC(ucp) /* XXX */
|
|
|
|
#define SET_RETURN_ADDR_JB(jb, ra) \
|
|
|
|
(jb)[0]._jb[_JB_PC] = (long)(ra) - 8
|
2000-10-13 22:12:32 +00:00
|
|
|
#else
|
|
|
|
#error "Don't recognize this architecture!"
|
|
|
|
#endif
|
|
|
|
|
1996-01-22 00:23:58 +00:00
|
|
|
/*
|
|
|
|
* Kernel fatal error handler macro.
|
|
|
|
*/
|
|
|
|
#define PANIC(string) _thread_exit(__FILE__,__LINE__,string)
|
|
|
|
|
2000-10-13 22:12:32 +00:00
|
|
|
|
1998-04-29 09:59:34 +00:00
|
|
|
/* Output debug messages like this: */
|
2000-10-13 22:12:32 +00:00
|
|
|
#define stdout_debug(args...) do { \
|
|
|
|
char buf[128]; \
|
|
|
|
snprintf(buf, sizeof(buf), ##args); \
|
2001-01-31 02:16:57 +00:00
|
|
|
__sys_write(1, buf, strlen(buf)); \
|
2000-10-13 22:12:32 +00:00
|
|
|
} while (0)
|
|
|
|
#define stderr_debug(args...) do { \
|
|
|
|
char buf[128]; \
|
|
|
|
snprintf(buf, sizeof(buf), ##args); \
|
2001-01-31 02:16:57 +00:00
|
|
|
__sys_write(2, buf, strlen(buf)); \
|
2000-10-13 22:12:32 +00:00
|
|
|
} while (0)
|
|
|
|
|
1998-04-29 09:59:34 +00:00
|
|
|
|
1999-03-23 05:07:56 +00:00
|
|
|
|
1997-02-05 23:26:09 +00:00
|
|
|
/*
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
* Priority queue manipulation macros (using pqe link):
|
1997-02-05 23:26:09 +00:00
|
|
|
*/
|
1999-03-23 05:07:56 +00:00
|
|
|
#define PTHREAD_PRIOQ_INSERT_HEAD(thrd) _pq_insert_head(&_readyq,thrd)
|
|
|
|
#define PTHREAD_PRIOQ_INSERT_TAIL(thrd) _pq_insert_tail(&_readyq,thrd)
|
|
|
|
#define PTHREAD_PRIOQ_REMOVE(thrd) _pq_remove(&_readyq,thrd)
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
#define PTHREAD_PRIOQ_FIRST() _pq_first(&_readyq)
|
1999-03-23 05:07:56 +00:00
|
|
|
|
|
|
|
/*
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
* Waiting queue manipulation macros (using pqe link):
|
1999-03-23 05:07:56 +00:00
|
|
|
*/
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
#define PTHREAD_WAITQ_REMOVE(thrd) _waitq_remove(thrd)
|
|
|
|
#define PTHREAD_WAITQ_INSERT(thrd) _waitq_insert(thrd)
|
2000-10-13 22:12:32 +00:00
|
|
|
|
|
|
|
#if defined(_PTHREADS_INVARIANTS)
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
#define PTHREAD_WAITQ_CLEARACTIVE() _waitq_clearactive()
|
|
|
|
#define PTHREAD_WAITQ_SETACTIVE() _waitq_setactive()
|
|
|
|
#else
|
|
|
|
#define PTHREAD_WAITQ_CLEARACTIVE()
|
|
|
|
#define PTHREAD_WAITQ_SETACTIVE()
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Work queue manipulation macros (using qe link):
|
|
|
|
*/
|
|
|
|
#define PTHREAD_WORKQ_INSERT(thrd) do { \
|
|
|
|
TAILQ_INSERT_TAIL(&_workq,thrd,qe); \
|
|
|
|
(thrd)->flags |= PTHREAD_FLAGS_IN_WORKQ; \
|
|
|
|
} while (0)
|
|
|
|
#define PTHREAD_WORKQ_REMOVE(thrd) do { \
|
|
|
|
TAILQ_REMOVE(&_workq,thrd,qe); \
|
|
|
|
(thrd)->flags &= ~PTHREAD_FLAGS_IN_WORKQ; \
|
|
|
|
} while (0)
|
|
|
|
|
1999-03-23 05:07:56 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* State change macro without scheduling queue change:
|
|
|
|
*/
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
#define PTHREAD_SET_STATE(thrd, newstate) do { \
|
1997-02-05 23:26:09 +00:00
|
|
|
(thrd)->state = newstate; \
|
|
|
|
(thrd)->fname = __FILE__; \
|
|
|
|
(thrd)->lineno = __LINE__; \
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
} while (0)
|
1997-02-05 23:26:09 +00:00
|
|
|
|
1999-03-23 05:07:56 +00:00
|
|
|
/*
|
|
|
|
* State change macro with scheduling queue change - This must be
|
|
|
|
* called with preemption deferred (see thread_kern_sched_[un]defer).
|
|
|
|
*/
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
#if defined(_PTHREADS_INVARIANTS)
|
2000-10-13 22:12:32 +00:00
|
|
|
#include <assert.h>
|
|
|
|
#define PTHREAD_ASSERT(cond, msg) do { \
|
|
|
|
if (!(cond)) \
|
|
|
|
PANIC(msg); \
|
|
|
|
} while (0)
|
|
|
|
#define PTHREAD_ASSERT_NOT_IN_SYNCQ(thrd) \
|
|
|
|
PTHREAD_ASSERT((((thrd)->flags & PTHREAD_FLAGS_IN_SYNCQ) == 0), \
|
|
|
|
"Illegal call from signal handler");
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
#define PTHREAD_NEW_STATE(thrd, newstate) do { \
|
|
|
|
if (_thread_kern_new_state != 0) \
|
|
|
|
PANIC("Recursive PTHREAD_NEW_STATE"); \
|
|
|
|
_thread_kern_new_state = 1; \
|
|
|
|
if ((thrd)->state != newstate) { \
|
|
|
|
if ((thrd)->state == PS_RUNNING) { \
|
|
|
|
PTHREAD_PRIOQ_REMOVE(thrd); \
|
2002-05-24 04:32:28 +00:00
|
|
|
PTHREAD_SET_STATE(thrd, newstate); \
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
PTHREAD_WAITQ_INSERT(thrd); \
|
|
|
|
} else if (newstate == PS_RUNNING) { \
|
|
|
|
PTHREAD_WAITQ_REMOVE(thrd); \
|
2002-05-24 04:32:28 +00:00
|
|
|
PTHREAD_SET_STATE(thrd, newstate); \
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
PTHREAD_PRIOQ_INSERT_TAIL(thrd); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
_thread_kern_new_state = 0; \
|
|
|
|
} while (0)
|
|
|
|
#else
|
2000-10-13 22:12:32 +00:00
|
|
|
#define PTHREAD_ASSERT(cond, msg)
|
|
|
|
#define PTHREAD_ASSERT_NOT_IN_SYNCQ(thrd)
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
#define PTHREAD_NEW_STATE(thrd, newstate) do { \
|
1999-03-23 05:07:56 +00:00
|
|
|
if ((thrd)->state != newstate) { \
|
|
|
|
if ((thrd)->state == PS_RUNNING) { \
|
|
|
|
PTHREAD_PRIOQ_REMOVE(thrd); \
|
|
|
|
PTHREAD_WAITQ_INSERT(thrd); \
|
|
|
|
} else if (newstate == PS_RUNNING) { \
|
|
|
|
PTHREAD_WAITQ_REMOVE(thrd); \
|
|
|
|
PTHREAD_PRIOQ_INSERT_TAIL(thrd); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
PTHREAD_SET_STATE(thrd, newstate); \
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
} while (0)
|
|
|
|
#endif
|
1999-03-23 05:07:56 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Define the signals to be used for scheduling.
|
|
|
|
*/
|
|
|
|
#if defined(_PTHREADS_COMPAT_SCHED)
|
|
|
|
#define _ITIMER_SCHED_TIMER ITIMER_VIRTUAL
|
|
|
|
#define _SCHED_SIGNAL SIGVTALRM
|
|
|
|
#else
|
|
|
|
#define _ITIMER_SCHED_TIMER ITIMER_PROF
|
|
|
|
#define _SCHED_SIGNAL SIGPROF
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Priority queues.
|
|
|
|
*
|
|
|
|
* XXX It'd be nice if these were contained in uthread_priority_queue.[ch].
|
|
|
|
*/
|
|
|
|
typedef struct pq_list {
|
2000-05-26 02:09:24 +00:00
|
|
|
TAILQ_HEAD(, pthread) pl_head; /* list of threads at this priority */
|
|
|
|
TAILQ_ENTRY(pq_list) pl_link; /* link for queue of priority lists */
|
1999-03-23 05:07:56 +00:00
|
|
|
int pl_prio; /* the priority of this list */
|
|
|
|
int pl_queued; /* is this in the priority queue */
|
|
|
|
} pq_list_t;
|
|
|
|
|
|
|
|
typedef struct pq_queue {
|
2000-05-26 02:09:24 +00:00
|
|
|
TAILQ_HEAD(, pq_list) pq_queue; /* queue of priority lists */
|
1999-03-23 05:07:56 +00:00
|
|
|
pq_list_t *pq_lists; /* array of all priority lists */
|
|
|
|
int pq_size; /* number of priority lists */
|
|
|
|
} pq_queue_t;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TailQ initialization values.
|
|
|
|
*/
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
#define TAILQ_INITIALIZER { NULL, NULL }
|
1999-03-23 05:07:56 +00:00
|
|
|
|
1996-08-20 08:22:01 +00:00
|
|
|
/*
|
|
|
|
* Mutex definitions.
|
|
|
|
*/
|
|
|
|
union pthread_mutex_data {
|
|
|
|
void *m_ptr;
|
|
|
|
int m_count;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pthread_mutex {
|
|
|
|
enum pthread_mutextype m_type;
|
1999-03-23 05:07:56 +00:00
|
|
|
int m_protocol;
|
2000-05-26 02:09:24 +00:00
|
|
|
TAILQ_HEAD(mutex_head, pthread) m_queue;
|
1996-08-20 08:22:01 +00:00
|
|
|
struct pthread *m_owner;
|
|
|
|
union pthread_mutex_data m_data;
|
|
|
|
long m_flags;
|
1999-03-23 05:07:56 +00:00
|
|
|
int m_refcount;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Used for priority inheritence and protection.
|
|
|
|
*
|
|
|
|
* m_prio - For priority inheritence, the highest active
|
|
|
|
* priority (threads locking the mutex inherit
|
|
|
|
* this priority). For priority protection, the
|
|
|
|
* ceiling priority of this mutex.
|
|
|
|
* m_saved_prio - mutex owners inherited priority before
|
|
|
|
* taking the mutex, restored when the owner
|
|
|
|
* unlocks the mutex.
|
|
|
|
*/
|
|
|
|
int m_prio;
|
|
|
|
int m_saved_prio;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Link for list of all mutexes a thread currently owns.
|
|
|
|
*/
|
2000-05-26 02:09:24 +00:00
|
|
|
TAILQ_ENTRY(pthread_mutex) m_qe;
|
1998-04-29 09:59:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Lock for accesses to this structure.
|
|
|
|
*/
|
1998-06-09 23:02:43 +00:00
|
|
|
spinlock_t lock;
|
1996-08-20 08:22:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Flags for mutexes.
|
|
|
|
*/
|
|
|
|
#define MUTEX_FLAGS_PRIVATE 0x01
|
|
|
|
#define MUTEX_FLAGS_INITED 0x02
|
|
|
|
#define MUTEX_FLAGS_BUSY 0x04
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Static mutex initialization values.
|
|
|
|
*/
|
1998-04-04 10:58:12 +00:00
|
|
|
#define PTHREAD_MUTEX_STATIC_INITIALIZER \
|
1999-03-23 05:07:56 +00:00
|
|
|
{ PTHREAD_MUTEX_DEFAULT, PTHREAD_PRIO_NONE, TAILQ_INITIALIZER, \
|
1999-11-28 05:38:13 +00:00
|
|
|
NULL, { NULL }, MUTEX_FLAGS_PRIVATE, 0, 0, 0, TAILQ_INITIALIZER, \
|
1999-05-23 10:55:33 +00:00
|
|
|
_SPINLOCK_INITIALIZER }
|
1996-08-20 08:22:01 +00:00
|
|
|
|
|
|
|
struct pthread_mutex_attr {
|
|
|
|
enum pthread_mutextype m_type;
|
1999-03-23 05:07:56 +00:00
|
|
|
int m_protocol;
|
|
|
|
int m_ceiling;
|
1996-08-20 08:22:01 +00:00
|
|
|
long m_flags;
|
|
|
|
};
|
|
|
|
|
2001-01-24 13:03:38 +00:00
|
|
|
#define PTHREAD_MUTEXATTR_STATIC_INITIALIZER \
|
|
|
|
{ PTHREAD_MUTEX_DEFAULT, PTHREAD_PRIO_NONE, 0, MUTEX_FLAGS_PRIVATE }
|
|
|
|
|
1996-08-20 08:22:01 +00:00
|
|
|
/*
|
|
|
|
* Condition variable definitions.
|
|
|
|
*/
|
|
|
|
enum pthread_cond_type {
|
|
|
|
COND_TYPE_FAST,
|
|
|
|
COND_TYPE_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pthread_cond {
|
1999-03-23 05:07:56 +00:00
|
|
|
enum pthread_cond_type c_type;
|
2000-05-26 02:09:24 +00:00
|
|
|
TAILQ_HEAD(cond_head, pthread) c_queue;
|
1999-03-23 05:07:56 +00:00
|
|
|
pthread_mutex_t c_mutex;
|
|
|
|
void *c_data;
|
|
|
|
long c_flags;
|
2000-11-09 05:08:26 +00:00
|
|
|
int c_seqno;
|
1998-04-29 09:59:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Lock for accesses to this structure.
|
|
|
|
*/
|
1999-03-23 05:07:56 +00:00
|
|
|
spinlock_t lock;
|
1996-08-20 08:22:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct pthread_cond_attr {
|
|
|
|
enum pthread_cond_type c_type;
|
|
|
|
long c_flags;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Flags for condition variables.
|
|
|
|
*/
|
|
|
|
#define COND_FLAGS_PRIVATE 0x01
|
|
|
|
#define COND_FLAGS_INITED 0x02
|
|
|
|
#define COND_FLAGS_BUSY 0x04
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Static cond initialization values.
|
|
|
|
*/
|
1998-04-04 10:58:12 +00:00
|
|
|
#define PTHREAD_COND_STATIC_INITIALIZER \
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
{ COND_TYPE_FAST, TAILQ_INITIALIZER, NULL, NULL, \
|
2000-11-09 05:08:26 +00:00
|
|
|
0, 0, _SPINLOCK_INITIALIZER }
|
1996-08-20 08:22:01 +00:00
|
|
|
|
2000-01-20 07:54:49 +00:00
|
|
|
/*
|
|
|
|
* Semaphore definitions.
|
|
|
|
*/
|
|
|
|
struct sem {
|
|
|
|
#define SEM_MAGIC ((u_int32_t) 0x09fa4012)
|
|
|
|
u_int32_t magic;
|
|
|
|
pthread_mutex_t lock;
|
|
|
|
pthread_cond_t gtzero;
|
|
|
|
u_int32_t count;
|
|
|
|
u_int32_t nwaiters;
|
|
|
|
};
|
|
|
|
|
1996-08-20 08:22:01 +00:00
|
|
|
/*
|
|
|
|
* Cleanup definitions.
|
|
|
|
*/
|
|
|
|
struct pthread_cleanup {
|
|
|
|
struct pthread_cleanup *next;
|
|
|
|
void (*routine) ();
|
|
|
|
void *routine_arg;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pthread_attr {
|
1999-03-23 05:07:56 +00:00
|
|
|
int sched_policy;
|
|
|
|
int sched_inherit;
|
|
|
|
int sched_interval;
|
1996-08-20 08:22:01 +00:00
|
|
|
int prio;
|
1998-03-08 02:37:27 +00:00
|
|
|
int suspend;
|
|
|
|
int flags;
|
|
|
|
void *arg_attr;
|
|
|
|
void (*cleanup_attr) ();
|
|
|
|
void *stackaddr_attr;
|
|
|
|
size_t stacksize_attr;
|
2001-07-20 04:23:11 +00:00
|
|
|
size_t guardsize_attr;
|
1996-08-20 08:22:01 +00:00
|
|
|
};
|
|
|
|
|
1996-01-22 00:23:58 +00:00
|
|
|
/*
|
|
|
|
* Thread creation state attributes.
|
|
|
|
*/
|
|
|
|
#define PTHREAD_CREATE_RUNNING 0
|
|
|
|
#define PTHREAD_CREATE_SUSPENDED 1
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Miscellaneous definitions.
|
|
|
|
*/
|
2003-01-06 00:56:23 +00:00
|
|
|
#if !defined(__ia64__)
|
1996-01-22 00:23:58 +00:00
|
|
|
#define PTHREAD_STACK_DEFAULT 65536
|
2003-01-06 00:56:23 +00:00
|
|
|
#else
|
|
|
|
#define PTHREAD_STACK_DEFAULT 0x40000
|
|
|
|
#endif
|
1999-12-29 15:44:59 +00:00
|
|
|
/*
|
2001-07-20 04:23:11 +00:00
|
|
|
* Size of default red zone at the end of each stack. In actuality, this "red
|
|
|
|
* zone" is merely an unmapped region, except in the case of the initial stack.
|
|
|
|
* Since mmap() makes it possible to specify the maximum growth of a MAP_STACK
|
|
|
|
* region, an unmapped gap between thread stacks achieves the same effect as
|
|
|
|
* explicitly mapped red zones.
|
2002-05-13 07:58:15 +00:00
|
|
|
* This is declared and initialized in uthread_init.c.
|
1999-12-29 15:44:59 +00:00
|
|
|
*/
|
2002-05-15 05:37:48 +00:00
|
|
|
extern int _pthread_guard_default;
|
2002-05-13 07:58:15 +00:00
|
|
|
|
2002-05-15 05:37:48 +00:00
|
|
|
extern int _pthread_page_size;
|
1999-11-28 19:47:43 +00:00
|
|
|
|
1999-07-11 05:56:37 +00:00
|
|
|
/*
|
|
|
|
* Maximum size of initial thread's stack. This perhaps deserves to be larger
|
1999-07-06 00:25:38 +00:00
|
|
|
* than the stacks of other threads, since many applications are likely to run
|
1999-07-11 05:56:37 +00:00
|
|
|
* almost entirely on this stack.
|
|
|
|
*/
|
2003-01-06 00:56:23 +00:00
|
|
|
#if !defined(__ia64__)
|
1999-07-05 00:35:19 +00:00
|
|
|
#define PTHREAD_STACK_INITIAL 0x100000
|
2003-01-06 00:56:23 +00:00
|
|
|
#else
|
|
|
|
#define PTHREAD_STACK_INITIAL 0x400000
|
|
|
|
#endif
|
2000-10-13 22:12:32 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Define the different priority ranges. All applications have thread
|
|
|
|
* priorities constrained within 0-31. The threads library raises the
|
|
|
|
* priority when delivering signals in order to ensure that signal
|
|
|
|
* delivery happens (from the POSIX spec) "as soon as possible".
|
|
|
|
* In the future, the threads library will also be able to map specific
|
|
|
|
* threads into real-time (cooperating) processes or kernel threads.
|
|
|
|
* The RT and SIGNAL priorities will be used internally and added to
|
|
|
|
* thread base priorities so that the scheduling queue can handle both
|
|
|
|
* normal and RT priority threads with and without signal handling.
|
|
|
|
*
|
|
|
|
* The approach taken is that, within each class, signal delivery
|
|
|
|
* always has priority over thread execution.
|
|
|
|
*/
|
|
|
|
#define PTHREAD_DEFAULT_PRIORITY 15
|
1996-01-22 00:23:58 +00:00
|
|
|
#define PTHREAD_MIN_PRIORITY 0
|
2000-10-13 22:12:32 +00:00
|
|
|
#define PTHREAD_MAX_PRIORITY 31 /* 0x1F */
|
|
|
|
#define PTHREAD_SIGNAL_PRIORITY 32 /* 0x20 */
|
|
|
|
#define PTHREAD_RT_PRIORITY 64 /* 0x40 */
|
|
|
|
#define PTHREAD_FIRST_PRIORITY PTHREAD_MIN_PRIORITY
|
|
|
|
#define PTHREAD_LAST_PRIORITY \
|
|
|
|
(PTHREAD_MAX_PRIORITY + PTHREAD_SIGNAL_PRIORITY + PTHREAD_RT_PRIORITY)
|
|
|
|
#define PTHREAD_BASE_PRIORITY(prio) ((prio) & PTHREAD_MAX_PRIORITY)
|
1996-01-22 00:23:58 +00:00
|
|
|
|
|
|
|
/*
|
2000-10-13 22:12:32 +00:00
|
|
|
* Clock resolution in microseconds.
|
1996-01-22 00:23:58 +00:00
|
|
|
*/
|
2000-10-13 22:12:32 +00:00
|
|
|
#define CLOCK_RES_USEC 10000
|
2001-02-26 01:05:33 +00:00
|
|
|
#define CLOCK_RES_USEC_MIN 1000
|
1996-01-22 00:23:58 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Time slice period in microseconds.
|
|
|
|
*/
|
2000-10-13 22:12:32 +00:00
|
|
|
#define TIMESLICE_USEC 20000
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Define a thread-safe macro to get the current time of day
|
|
|
|
* which is updated at regular intervals by the scheduling signal
|
|
|
|
* handler.
|
|
|
|
*/
|
|
|
|
#define GET_CURRENT_TOD(tv) \
|
|
|
|
do { \
|
|
|
|
tv.tv_sec = _sched_tod.tv_sec; \
|
|
|
|
tv.tv_usec = _sched_tod.tv_usec; \
|
|
|
|
} while (tv.tv_sec != _sched_tod.tv_sec)
|
|
|
|
|
1996-01-22 00:23:58 +00:00
|
|
|
|
1998-09-07 19:01:43 +00:00
|
|
|
struct pthread_rwlockattr {
|
|
|
|
int pshared;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pthread_rwlock {
|
|
|
|
pthread_mutex_t lock; /* monitor lock */
|
|
|
|
int state; /* 0 = idle >0 = # of readers -1 = writer */
|
|
|
|
pthread_cond_t read_signal;
|
|
|
|
pthread_cond_t write_signal;
|
|
|
|
int blocked_writers;
|
|
|
|
};
|
|
|
|
|
1996-01-22 00:23:58 +00:00
|
|
|
/*
|
|
|
|
* Thread states.
|
|
|
|
*/
|
|
|
|
enum pthread_state {
|
|
|
|
PS_RUNNING,
|
|
|
|
PS_SIGTHREAD,
|
|
|
|
PS_MUTEX_WAIT,
|
|
|
|
PS_COND_WAIT,
|
|
|
|
PS_FDLR_WAIT,
|
|
|
|
PS_FDLW_WAIT,
|
|
|
|
PS_FDR_WAIT,
|
|
|
|
PS_FDW_WAIT,
|
1998-04-11 07:47:22 +00:00
|
|
|
PS_FILE_WAIT,
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
PS_POLL_WAIT,
|
1996-01-22 00:23:58 +00:00
|
|
|
PS_SELECT_WAIT,
|
|
|
|
PS_SLEEP_WAIT,
|
|
|
|
PS_WAIT_WAIT,
|
1998-09-30 06:22:07 +00:00
|
|
|
PS_SIGSUSPEND,
|
1996-01-22 00:23:58 +00:00
|
|
|
PS_SIGWAIT,
|
1999-03-23 05:07:56 +00:00
|
|
|
PS_SPINBLOCK,
|
1996-01-22 00:23:58 +00:00
|
|
|
PS_JOIN,
|
|
|
|
PS_SUSPENDED,
|
|
|
|
PS_DEAD,
|
1999-03-23 05:07:56 +00:00
|
|
|
PS_DEADLOCK,
|
1996-01-22 00:23:58 +00:00
|
|
|
PS_STATE_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* File descriptor locking definitions.
|
|
|
|
*/
|
|
|
|
#define FD_READ 0x1
|
|
|
|
#define FD_WRITE 0x2
|
|
|
|
#define FD_RDWR (FD_READ | FD_WRITE)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* File descriptor table structure.
|
|
|
|
*/
|
|
|
|
struct fd_table_entry {
|
1998-04-29 09:59:34 +00:00
|
|
|
/*
|
|
|
|
* Lock for accesses to this file descriptor table
|
|
|
|
* entry. This is passed to _spinlock() to provide atomic
|
|
|
|
* access to this structure. It does *not* represent the
|
|
|
|
* state of the lock on the file descriptor.
|
|
|
|
*/
|
1998-06-09 23:02:43 +00:00
|
|
|
spinlock_t lock;
|
2000-05-26 02:09:24 +00:00
|
|
|
TAILQ_HEAD(, pthread) r_queue; /* Read queue. */
|
|
|
|
TAILQ_HEAD(, pthread) w_queue; /* Write queue. */
|
1996-01-22 00:23:58 +00:00
|
|
|
struct pthread *r_owner; /* Ptr to thread owning read lock. */
|
|
|
|
struct pthread *w_owner; /* Ptr to thread owning write lock. */
|
|
|
|
char *r_fname; /* Ptr to read lock source file name */
|
|
|
|
int r_lineno; /* Read lock source line number. */
|
|
|
|
char *w_fname; /* Ptr to write lock source file name */
|
|
|
|
int w_lineno; /* Write lock source line number. */
|
|
|
|
int r_lockcount; /* Count for FILE read locks. */
|
|
|
|
int w_lockcount; /* Count for FILE write locks. */
|
|
|
|
int flags; /* Flags used in open. */
|
|
|
|
};
|
|
|
|
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
struct pthread_poll_data {
|
1996-01-22 00:23:58 +00:00
|
|
|
int nfds;
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
struct pollfd *fds;
|
1996-01-22 00:23:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
union pthread_wait_data {
|
1999-03-23 05:07:56 +00:00
|
|
|
pthread_mutex_t mutex;
|
|
|
|
pthread_cond_t cond;
|
1996-01-22 00:23:58 +00:00
|
|
|
const sigset_t *sigwait; /* Waiting on a signal in sigwait */
|
|
|
|
struct {
|
|
|
|
short fd; /* Used when thread waiting on fd */
|
|
|
|
short branch; /* Line number, for debugging. */
|
|
|
|
char *fname; /* Source file name for debugging.*/
|
|
|
|
} fd;
|
2000-10-13 22:12:32 +00:00
|
|
|
FILE *fp;
|
|
|
|
struct pthread_poll_data *poll_data;
|
1999-03-23 05:07:56 +00:00
|
|
|
spinlock_t *spinlock;
|
2001-08-16 06:31:32 +00:00
|
|
|
struct pthread *thread;
|
1996-01-22 00:23:58 +00:00
|
|
|
};
|
|
|
|
|
2000-01-19 07:04:50 +00:00
|
|
|
/*
|
|
|
|
* Define a continuation routine that can be used to perform a
|
|
|
|
* transfer of control:
|
|
|
|
*/
|
|
|
|
typedef void (*thread_continuation_t) (void *);
|
|
|
|
|
2000-11-09 05:08:26 +00:00
|
|
|
struct pthread_signal_frame;
|
|
|
|
|
2000-10-13 22:12:32 +00:00
|
|
|
struct pthread_state_data {
|
2000-11-09 05:08:26 +00:00
|
|
|
struct pthread_signal_frame *psd_curframe;
|
2000-10-13 22:12:32 +00:00
|
|
|
sigset_t psd_sigmask;
|
|
|
|
struct timespec psd_wakeup_time;
|
|
|
|
union pthread_wait_data psd_wait_data;
|
2000-11-09 05:08:26 +00:00
|
|
|
enum pthread_state psd_state;
|
|
|
|
int psd_flags;
|
|
|
|
int psd_interrupted;
|
|
|
|
int psd_longjmp_val;
|
|
|
|
int psd_sigmask_seqno;
|
|
|
|
int psd_signo;
|
|
|
|
int psd_sig_defer_count;
|
2000-10-13 22:12:32 +00:00
|
|
|
/* XXX - What about thread->timeout and/or thread->error? */
|
|
|
|
};
|
|
|
|
|
2001-11-17 14:28:39 +00:00
|
|
|
struct join_status {
|
|
|
|
struct pthread *thread;
|
2002-02-09 19:58:41 +00:00
|
|
|
void *ret;
|
2001-11-17 14:28:39 +00:00
|
|
|
int error;
|
|
|
|
};
|
2000-10-13 22:12:32 +00:00
|
|
|
|
|
|
|
/*
|
2002-02-09 19:58:41 +00:00
|
|
|
* The frame that is added to the top of a threads stack when setting up
|
|
|
|
* up the thread to run a signal handler.
|
2000-10-13 22:12:32 +00:00
|
|
|
*/
|
|
|
|
struct pthread_signal_frame {
|
|
|
|
/*
|
|
|
|
* This stores the threads state before the signal.
|
|
|
|
*/
|
|
|
|
struct pthread_state_data saved_state;
|
|
|
|
|
|
|
|
/*
|
2002-02-09 19:58:41 +00:00
|
|
|
* Threads return context; we use only jmp_buf's for now.
|
2000-10-13 22:12:32 +00:00
|
|
|
*/
|
|
|
|
union {
|
|
|
|
jmp_buf jb;
|
|
|
|
ucontext_t uc;
|
|
|
|
} ctx;
|
|
|
|
int signo; /* signal, arg 1 to sighandler */
|
|
|
|
int sig_has_args; /* use signal args if true */
|
2000-11-09 05:08:26 +00:00
|
|
|
ucontext_t uc;
|
|
|
|
siginfo_t siginfo;
|
2000-10-13 22:12:32 +00:00
|
|
|
};
|
|
|
|
|
2002-03-19 22:58:56 +00:00
|
|
|
struct pthread_specific_elem {
|
|
|
|
const void *data;
|
|
|
|
int seqno;
|
|
|
|
};
|
|
|
|
|
1996-01-22 00:23:58 +00:00
|
|
|
/*
|
|
|
|
* Thread structure.
|
|
|
|
*/
|
|
|
|
struct pthread {
|
1998-04-03 09:31:15 +00:00
|
|
|
/*
|
|
|
|
* Magic value to help recognize a valid thread structure
|
|
|
|
* from an invalid one:
|
|
|
|
*/
|
|
|
|
#define PTHREAD_MAGIC ((u_int32_t) 0xd09ba115)
|
|
|
|
u_int32_t magic;
|
1998-04-11 07:47:22 +00:00
|
|
|
char *name;
|
1999-11-28 19:47:43 +00:00
|
|
|
u_int64_t uniqueid; /* for gdb */
|
1998-04-03 09:31:15 +00:00
|
|
|
|
1998-04-29 09:59:34 +00:00
|
|
|
/*
|
|
|
|
* Lock for accesses to this thread structure.
|
|
|
|
*/
|
1998-06-09 23:02:43 +00:00
|
|
|
spinlock_t lock;
|
1998-04-29 09:59:34 +00:00
|
|
|
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
/* Queue entry for list of all threads: */
|
2000-05-26 02:09:24 +00:00
|
|
|
TAILQ_ENTRY(pthread) tle;
|
1996-01-22 00:23:58 +00:00
|
|
|
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
/* Queue entry for list of dead threads: */
|
2000-05-26 02:09:24 +00:00
|
|
|
TAILQ_ENTRY(pthread) dle;
|
1998-09-30 06:22:07 +00:00
|
|
|
|
1996-01-22 00:23:58 +00:00
|
|
|
/*
|
|
|
|
* Thread start routine, argument, stack pointer and thread
|
|
|
|
* attributes.
|
|
|
|
*/
|
1996-08-20 08:22:01 +00:00
|
|
|
void *(*start_routine)(void *);
|
|
|
|
void *arg;
|
|
|
|
void *stack;
|
|
|
|
struct pthread_attr attr;
|
1996-01-22 00:23:58 +00:00
|
|
|
|
2000-01-19 07:04:50 +00:00
|
|
|
/*
|
2002-02-09 19:58:41 +00:00
|
|
|
* Threads return context; we use only jmp_buf's for now.
|
2000-11-09 05:08:26 +00:00
|
|
|
*/
|
|
|
|
union {
|
|
|
|
jmp_buf jb;
|
|
|
|
ucontext_t uc;
|
|
|
|
} ctx;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Used for tracking delivery of signal handlers.
|
2000-01-19 07:04:50 +00:00
|
|
|
*/
|
2000-10-13 22:12:32 +00:00
|
|
|
struct pthread_signal_frame *curframe;
|
2000-01-19 07:04:50 +00:00
|
|
|
|
1999-11-28 05:38:13 +00:00
|
|
|
/*
|
|
|
|
* Cancelability flags - the lower 2 bits are used by cancel
|
|
|
|
* definitions in pthread.h
|
|
|
|
*/
|
|
|
|
#define PTHREAD_AT_CANCEL_POINT 0x0004
|
|
|
|
#define PTHREAD_CANCELLING 0x0008
|
|
|
|
#define PTHREAD_CANCEL_NEEDED 0x0010
|
|
|
|
int cancelflags;
|
|
|
|
|
2000-01-19 07:04:50 +00:00
|
|
|
thread_continuation_t continuation;
|
|
|
|
|
1996-01-22 00:23:58 +00:00
|
|
|
/*
|
1998-04-29 09:59:34 +00:00
|
|
|
* Current signal mask and pending signals.
|
1996-01-22 00:23:58 +00:00
|
|
|
*/
|
|
|
|
sigset_t sigmask;
|
1998-04-29 09:59:34 +00:00
|
|
|
sigset_t sigpend;
|
2000-11-09 05:08:26 +00:00
|
|
|
int sigmask_seqno;
|
2000-10-13 22:12:32 +00:00
|
|
|
int check_pending;
|
1996-01-22 00:23:58 +00:00
|
|
|
|
|
|
|
/* Thread state: */
|
|
|
|
enum pthread_state state;
|
|
|
|
|
2000-10-13 22:12:32 +00:00
|
|
|
/* Scheduling clock when this thread was last made active. */
|
|
|
|
long last_active;
|
1996-01-22 00:23:58 +00:00
|
|
|
|
2000-10-13 22:12:32 +00:00
|
|
|
/* Scheduling clock when this thread was last made inactive. */
|
|
|
|
long last_inactive;
|
1996-01-22 00:23:58 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Number of microseconds accumulated by this thread when
|
|
|
|
* time slicing is active.
|
|
|
|
*/
|
|
|
|
long slice_usec;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Time to wake up thread. This is used for sleeping threads and
|
|
|
|
* for any operation which may time out (such as select).
|
|
|
|
*/
|
|
|
|
struct timespec wakeup_time;
|
|
|
|
|
|
|
|
/* TRUE if operation has timed out. */
|
|
|
|
int timeout;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Error variable used instead of errno. The function __error()
|
|
|
|
* returns a pointer to this.
|
|
|
|
*/
|
|
|
|
int error;
|
|
|
|
|
2001-11-17 14:28:39 +00:00
|
|
|
/*
|
|
|
|
* The joiner is the thread that is joining to this thread. The
|
|
|
|
* join status keeps track of a join operation to another thread.
|
|
|
|
*/
|
|
|
|
struct pthread *joiner;
|
|
|
|
struct join_status join_status;
|
1996-01-22 00:23:58 +00:00
|
|
|
|
|
|
|
/*
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
* The current thread can belong to only one scheduling queue at
|
2000-10-13 22:12:32 +00:00
|
|
|
* a time (ready or waiting queue). It can also belong to:
|
1996-01-22 00:23:58 +00:00
|
|
|
*
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
* o A queue of threads waiting for a mutex
|
|
|
|
* o A queue of threads waiting for a condition variable
|
|
|
|
* o A queue of threads waiting for a file descriptor lock
|
|
|
|
* o A queue of threads needing work done by the kernel thread
|
|
|
|
* (waiting for a spinlock or file I/O)
|
1998-04-11 07:47:22 +00:00
|
|
|
*
|
2001-05-20 23:08:33 +00:00
|
|
|
* A thread can also be joining a thread (the joiner field above).
|
|
|
|
*
|
|
|
|
* It must not be possible for a thread to belong to any of the
|
|
|
|
* above queues while it is handling a signal. Signal handlers
|
|
|
|
* may longjmp back to previous stack frames circumventing normal
|
|
|
|
* control flow. This could corrupt queue integrity if the thread
|
|
|
|
* retains membership in the queue. Therefore, if a thread is a
|
2000-10-13 22:12:32 +00:00
|
|
|
* member of one of these queues when a signal handler is invoked,
|
2001-05-20 23:08:33 +00:00
|
|
|
* it must remove itself from the queue before calling the signal
|
|
|
|
* handler and reinsert itself after normal return of the handler.
|
2000-10-13 22:12:32 +00:00
|
|
|
*
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
* Use pqe for the scheduling queue link (both ready and waiting),
|
2001-05-20 23:08:33 +00:00
|
|
|
* sqe for synchronization (mutex and condition variable) queue
|
|
|
|
* links, and qe for all other links.
|
1996-01-22 00:23:58 +00:00
|
|
|
*/
|
2000-10-13 22:12:32 +00:00
|
|
|
TAILQ_ENTRY(pthread) pqe; /* priority queue link */
|
|
|
|
TAILQ_ENTRY(pthread) sqe; /* synchronization queue link */
|
|
|
|
TAILQ_ENTRY(pthread) qe; /* all other queues link */
|
1998-04-11 07:47:22 +00:00
|
|
|
|
1996-01-22 00:23:58 +00:00
|
|
|
/* Wait data. */
|
|
|
|
union pthread_wait_data data;
|
|
|
|
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
/*
|
|
|
|
* Allocated for converting select into poll.
|
|
|
|
*/
|
|
|
|
struct pthread_poll_data poll_data;
|
|
|
|
|
1997-02-05 23:26:09 +00:00
|
|
|
/*
|
|
|
|
* Set to TRUE if a blocking operation was
|
|
|
|
* interrupted by a signal:
|
|
|
|
*/
|
|
|
|
int interrupted;
|
|
|
|
|
|
|
|
/* Signal number when in state PS_SIGWAIT: */
|
|
|
|
int signo;
|
|
|
|
|
1999-03-23 05:07:56 +00:00
|
|
|
/*
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
* Set to non-zero when this thread has deferred signals.
|
|
|
|
* We allow for recursive deferral.
|
1999-03-23 05:07:56 +00:00
|
|
|
*/
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
int sig_defer_count;
|
1999-03-23 05:07:56 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set to TRUE if this thread should yield after undeferring
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
* signals.
|
1999-03-23 05:07:56 +00:00
|
|
|
*/
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
int yield_on_sig_undefer;
|
1999-03-23 05:07:56 +00:00
|
|
|
|
1999-11-28 05:38:13 +00:00
|
|
|
/* Miscellaneous flags; only set with signals deferred. */
|
1999-03-23 05:07:56 +00:00
|
|
|
int flags;
|
|
|
|
#define PTHREAD_FLAGS_PRIVATE 0x0001
|
|
|
|
#define PTHREAD_EXITING 0x0002
|
2000-10-13 22:12:32 +00:00
|
|
|
#define PTHREAD_FLAGS_IN_WAITQ 0x0004 /* in waiting queue using pqe link */
|
|
|
|
#define PTHREAD_FLAGS_IN_PRIOQ 0x0008 /* in priority queue using pqe link */
|
|
|
|
#define PTHREAD_FLAGS_IN_WORKQ 0x0010 /* in work queue using qe link */
|
|
|
|
#define PTHREAD_FLAGS_IN_FILEQ 0x0020 /* in file lock queue using qe link */
|
|
|
|
#define PTHREAD_FLAGS_IN_FDQ 0x0040 /* in fd lock queue using qe link */
|
|
|
|
#define PTHREAD_FLAGS_IN_CONDQ 0x0080 /* in condition queue using sqe link*/
|
|
|
|
#define PTHREAD_FLAGS_IN_MUTEXQ 0x0100 /* in mutex queue using sqe link */
|
2002-05-24 04:32:28 +00:00
|
|
|
#define PTHREAD_FLAGS_SUSPENDED 0x0200 /* thread is suspended */
|
|
|
|
#define PTHREAD_FLAGS_TRACE 0x0400 /* for debugging purposes */
|
2000-10-13 22:12:32 +00:00
|
|
|
#define PTHREAD_FLAGS_IN_SYNCQ \
|
2001-05-20 23:08:33 +00:00
|
|
|
(PTHREAD_FLAGS_IN_CONDQ | PTHREAD_FLAGS_IN_MUTEXQ)
|
1999-03-23 05:07:56 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Base priority is the user setable and retrievable priority
|
|
|
|
* of the thread. It is only affected by explicit calls to
|
|
|
|
* set thread priority and upon thread creation via a thread
|
|
|
|
* attribute or default priority.
|
|
|
|
*/
|
|
|
|
char base_priority;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Inherited priority is the priority a thread inherits by
|
|
|
|
* taking a priority inheritence or protection mutex. It
|
|
|
|
* is not affected by base priority changes. Inherited
|
|
|
|
* priority defaults to and remains 0 until a mutex is taken
|
|
|
|
* that is being waited on by any other thread whose priority
|
|
|
|
* is non-zero.
|
|
|
|
*/
|
|
|
|
char inherited_priority;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Active priority is always the maximum of the threads base
|
|
|
|
* priority and inherited priority. When there is a change
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
* in either the base or inherited priority, the active
|
1999-03-23 05:07:56 +00:00
|
|
|
* priority must be recalculated.
|
|
|
|
*/
|
|
|
|
char active_priority;
|
|
|
|
|
|
|
|
/* Number of priority ceiling or protection mutexes owned. */
|
|
|
|
int priority_mutex_count;
|
|
|
|
|
2004-01-08 15:39:12 +00:00
|
|
|
/* Number rwlocks rdlocks held. */
|
|
|
|
int rdlock_count;
|
|
|
|
|
1999-03-23 05:07:56 +00:00
|
|
|
/*
|
|
|
|
* Queue of currently owned mutexes.
|
|
|
|
*/
|
2000-05-26 02:09:24 +00:00
|
|
|
TAILQ_HEAD(, pthread_mutex) mutexq;
|
1999-03-23 05:07:56 +00:00
|
|
|
|
2002-03-19 22:58:56 +00:00
|
|
|
void *ret;
|
|
|
|
struct pthread_specific_elem *specific;
|
|
|
|
int specific_data_count;
|
1996-01-22 00:23:58 +00:00
|
|
|
|
|
|
|
/* Cleanup handlers Link List */
|
|
|
|
struct pthread_cleanup *cleanup;
|
1997-02-05 23:26:09 +00:00
|
|
|
char *fname; /* Ptr to source file name */
|
|
|
|
int lineno; /* Source line number. */
|
1996-01-22 00:23:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Global variables for the uthread kernel.
|
|
|
|
*/
|
|
|
|
|
2001-10-26 21:19:22 +00:00
|
|
|
SCLASS void *_usrstack
|
|
|
|
#ifdef GLOBAL_PTHREAD_PRIVATE
|
|
|
|
= (void *) USRSTACK;
|
|
|
|
#else
|
|
|
|
;
|
|
|
|
#endif
|
|
|
|
|
1996-01-22 00:23:58 +00:00
|
|
|
/* Kernel thread structure used when there are no running threads: */
|
|
|
|
SCLASS struct pthread _thread_kern_thread;
|
|
|
|
|
|
|
|
/* Ptr to the thread structure for the running thread: */
|
1997-02-05 23:26:09 +00:00
|
|
|
SCLASS struct pthread * volatile _thread_run
|
1996-01-22 00:23:58 +00:00
|
|
|
#ifdef GLOBAL_PTHREAD_PRIVATE
|
|
|
|
= &_thread_kern_thread;
|
|
|
|
#else
|
|
|
|
;
|
|
|
|
#endif
|
|
|
|
|
1999-03-23 05:07:56 +00:00
|
|
|
/* Ptr to the thread structure for the last user thread to run: */
|
|
|
|
SCLASS struct pthread * volatile _last_user_thread
|
|
|
|
#ifdef GLOBAL_PTHREAD_PRIVATE
|
|
|
|
= &_thread_kern_thread;
|
|
|
|
#else
|
|
|
|
;
|
|
|
|
#endif
|
|
|
|
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
/* List of all threads: */
|
2000-05-26 02:09:24 +00:00
|
|
|
SCLASS TAILQ_HEAD(, pthread) _thread_list
|
1996-01-22 00:23:58 +00:00
|
|
|
#ifdef GLOBAL_PTHREAD_PRIVATE
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
= TAILQ_HEAD_INITIALIZER(_thread_list);
|
1996-01-22 00:23:58 +00:00
|
|
|
#else
|
|
|
|
;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Array of kernel pipe file descriptors that are used to ensure that
|
1998-04-29 09:59:34 +00:00
|
|
|
* no signals are missed in calls to _select.
|
1996-01-22 00:23:58 +00:00
|
|
|
*/
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
SCLASS int _thread_kern_pipe[2]
|
1996-01-22 00:23:58 +00:00
|
|
|
#ifdef GLOBAL_PTHREAD_PRIVATE
|
|
|
|
= {
|
|
|
|
-1,
|
|
|
|
-1
|
|
|
|
};
|
|
|
|
#else
|
|
|
|
;
|
|
|
|
#endif
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
SCLASS int volatile _queue_signals
|
1996-01-22 00:23:58 +00:00
|
|
|
#ifdef GLOBAL_PTHREAD_PRIVATE
|
|
|
|
= 0;
|
|
|
|
#else
|
|
|
|
;
|
|
|
|
#endif
|
1998-04-29 09:59:34 +00:00
|
|
|
SCLASS int _thread_kern_in_sched
|
|
|
|
#ifdef GLOBAL_PTHREAD_PRIVATE
|
|
|
|
= 0;
|
|
|
|
#else
|
|
|
|
;
|
|
|
|
#endif
|
1996-01-22 00:23:58 +00:00
|
|
|
|
2000-10-13 22:12:32 +00:00
|
|
|
SCLASS int _sig_in_handler
|
|
|
|
#ifdef GLOBAL_PTHREAD_PRIVATE
|
|
|
|
= 0;
|
|
|
|
#else
|
|
|
|
;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Time of day at last scheduling timer signal: */
|
|
|
|
SCLASS struct timeval volatile _sched_tod
|
1996-01-22 00:23:58 +00:00
|
|
|
#ifdef GLOBAL_PTHREAD_PRIVATE
|
|
|
|
= { 0, 0 };
|
|
|
|
#else
|
|
|
|
;
|
|
|
|
#endif
|
|
|
|
|
2000-10-13 22:12:32 +00:00
|
|
|
/*
|
|
|
|
* Current scheduling timer ticks; used as resource usage.
|
|
|
|
*/
|
|
|
|
SCLASS unsigned int volatile _sched_ticks
|
|
|
|
#ifdef GLOBAL_PTHREAD_PRIVATE
|
|
|
|
= 0;
|
|
|
|
#else
|
|
|
|
;
|
|
|
|
#endif
|
|
|
|
|
1996-01-22 00:23:58 +00:00
|
|
|
/* Dead threads: */
|
2000-05-26 02:09:24 +00:00
|
|
|
SCLASS TAILQ_HEAD(, pthread) _dead_list
|
1996-01-22 00:23:58 +00:00
|
|
|
#ifdef GLOBAL_PTHREAD_PRIVATE
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
= TAILQ_HEAD_INITIALIZER(_dead_list);
|
1996-01-22 00:23:58 +00:00
|
|
|
#else
|
|
|
|
;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Initial thread: */
|
|
|
|
SCLASS struct pthread *_thread_initial
|
|
|
|
#ifdef GLOBAL_PTHREAD_PRIVATE
|
|
|
|
= NULL;
|
|
|
|
#else
|
|
|
|
;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Default thread attributes: */
|
2002-11-13 18:13:26 +00:00
|
|
|
SCLASS struct pthread_attr _pthread_attr_default
|
1996-01-22 00:23:58 +00:00
|
|
|
#ifdef GLOBAL_PTHREAD_PRIVATE
|
2001-07-20 04:23:11 +00:00
|
|
|
= { SCHED_RR, 0, TIMESLICE_USEC, PTHREAD_DEFAULT_PRIORITY,
|
|
|
|
PTHREAD_CREATE_RUNNING, PTHREAD_CREATE_JOINABLE, NULL, NULL, NULL,
|
2002-05-13 07:58:15 +00:00
|
|
|
PTHREAD_STACK_DEFAULT, -1 };
|
1996-01-22 00:23:58 +00:00
|
|
|
#else
|
|
|
|
;
|
|
|
|
#endif
|
|
|
|
|
1997-02-05 23:26:09 +00:00
|
|
|
/* Default mutex attributes: */
|
2002-11-13 18:13:26 +00:00
|
|
|
#define PTHREAD_MUTEXATTR_DEFAULT \
|
|
|
|
{ PTHREAD_MUTEX_DEFAULT, PTHREAD_PRIO_NONE, 0, 0 }
|
1996-11-11 09:07:05 +00:00
|
|
|
|
1997-02-05 23:26:09 +00:00
|
|
|
/* Default condition variable attributes: */
|
2002-11-13 18:13:26 +00:00
|
|
|
#define PTHREAD_CONDATTR_DEFAULT { COND_TYPE_FAST, 0 }
|
1997-02-05 23:26:09 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Standard I/O file descriptors need special flag treatment since
|
|
|
|
* setting one to non-blocking does all on *BSD. Sigh. This array
|
|
|
|
* is used to store the initial flag settings.
|
|
|
|
*/
|
|
|
|
SCLASS int _pthread_stdio_flags[3];
|
|
|
|
|
1996-01-22 00:23:58 +00:00
|
|
|
/* File table information: */
|
|
|
|
SCLASS struct fd_table_entry **_thread_fd_table
|
|
|
|
#ifdef GLOBAL_PTHREAD_PRIVATE
|
|
|
|
= NULL;
|
|
|
|
#else
|
|
|
|
;
|
|
|
|
#endif
|
|
|
|
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
/* Table for polling file descriptors: */
|
|
|
|
SCLASS struct pollfd *_thread_pfd_table
|
|
|
|
#ifdef GLOBAL_PTHREAD_PRIVATE
|
|
|
|
= NULL;
|
|
|
|
#else
|
|
|
|
;
|
|
|
|
#endif
|
|
|
|
|
1996-01-22 00:23:58 +00:00
|
|
|
SCLASS const int dtablecount
|
|
|
|
#ifdef GLOBAL_PTHREAD_PRIVATE
|
|
|
|
= 4096/sizeof(struct fd_table_entry);
|
|
|
|
#else
|
|
|
|
;
|
|
|
|
#endif
|
|
|
|
SCLASS int _thread_dtablesize /* Descriptor table size. */
|
|
|
|
#ifdef GLOBAL_PTHREAD_PRIVATE
|
1999-08-05 12:08:10 +00:00
|
|
|
= 0;
|
1996-01-22 00:23:58 +00:00
|
|
|
#else
|
|
|
|
;
|
|
|
|
#endif
|
|
|
|
|
2000-10-13 22:12:32 +00:00
|
|
|
SCLASS int _clock_res_usec /* Clock resolution in usec. */
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
#ifdef GLOBAL_PTHREAD_PRIVATE
|
2000-10-13 22:12:32 +00:00
|
|
|
= CLOCK_RES_USEC;
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
#else
|
|
|
|
;
|
|
|
|
#endif
|
|
|
|
|
1998-09-30 06:22:07 +00:00
|
|
|
/* Garbage collector mutex and condition variable. */
|
|
|
|
SCLASS pthread_mutex_t _gc_mutex
|
|
|
|
#ifdef GLOBAL_PTHREAD_PRIVATE
|
|
|
|
= NULL
|
|
|
|
#endif
|
|
|
|
;
|
|
|
|
SCLASS pthread_cond_t _gc_cond
|
|
|
|
#ifdef GLOBAL_PTHREAD_PRIVATE
|
|
|
|
= NULL
|
|
|
|
#endif
|
|
|
|
;
|
|
|
|
|
1998-04-29 09:59:34 +00:00
|
|
|
/*
|
|
|
|
* Array of signal actions for this process.
|
|
|
|
*/
|
Change signal handling to conform to POSIX specified semantics.
Before this change, a signal was delivered to each thread that
didn't have the signal masked. Signals also improperly woke up
threads waiting on I/O. With this change, signals are now
handled in the following way:
o If a thread is waiting in a sigwait for the signal,
then the thread is woken up.
o If no threads are sigwait'ing on the signal and a
thread is in a sigsuspend waiting for the signal,
then the thread is woken up.
o In the case that no threads are waiting or suspended
on the signal, then the signal is delivered to the
first thread we find that has the signal unmasked.
o If no threads are waiting or suspended on the signal,
and no threads have the signal unmasked, then the signal
is added to the process wide pending signal set. The
signal will be delivered to the first thread that unmasks
the signal.
If there is an installed signal handler, it is only invoked
if the chosen thread was not in a sigwait.
In the case that multiple threads are waiting or suspended
on a signal, or multiple threads have the signal unmasked,
we wake up/deliver the signal to the first thread we find.
The above rules still apply.
Reported by: Scott Hess <scott@avantgo.com>
Reviewed by: jb, jasone
1999-12-04 22:55:59 +00:00
|
|
|
SCLASS struct sigaction _thread_sigact[NSIG];
|
|
|
|
|
2000-06-27 21:30:16 +00:00
|
|
|
/*
|
|
|
|
* Array of counts of dummy handlers for SIG_DFL signals. This is used to
|
|
|
|
* assure that there is always a dummy signal handler installed while there is a
|
|
|
|
* thread sigwait()ing on the corresponding signal.
|
|
|
|
*/
|
|
|
|
SCLASS int _thread_dfl_count[NSIG];
|
|
|
|
|
Change signal handling to conform to POSIX specified semantics.
Before this change, a signal was delivered to each thread that
didn't have the signal masked. Signals also improperly woke up
threads waiting on I/O. With this change, signals are now
handled in the following way:
o If a thread is waiting in a sigwait for the signal,
then the thread is woken up.
o If no threads are sigwait'ing on the signal and a
thread is in a sigsuspend waiting for the signal,
then the thread is woken up.
o In the case that no threads are waiting or suspended
on the signal, then the signal is delivered to the
first thread we find that has the signal unmasked.
o If no threads are waiting or suspended on the signal,
and no threads have the signal unmasked, then the signal
is added to the process wide pending signal set. The
signal will be delivered to the first thread that unmasks
the signal.
If there is an installed signal handler, it is only invoked
if the chosen thread was not in a sigwait.
In the case that multiple threads are waiting or suspended
on a signal, or multiple threads have the signal unmasked,
we wake up/deliver the signal to the first thread we find.
The above rules still apply.
Reported by: Scott Hess <scott@avantgo.com>
Reviewed by: jb, jasone
1999-12-04 22:55:59 +00:00
|
|
|
/*
|
2000-10-13 22:12:32 +00:00
|
|
|
* Pending signals and mask for this process:
|
Change signal handling to conform to POSIX specified semantics.
Before this change, a signal was delivered to each thread that
didn't have the signal masked. Signals also improperly woke up
threads waiting on I/O. With this change, signals are now
handled in the following way:
o If a thread is waiting in a sigwait for the signal,
then the thread is woken up.
o If no threads are sigwait'ing on the signal and a
thread is in a sigsuspend waiting for the signal,
then the thread is woken up.
o In the case that no threads are waiting or suspended
on the signal, then the signal is delivered to the
first thread we find that has the signal unmasked.
o If no threads are waiting or suspended on the signal,
and no threads have the signal unmasked, then the signal
is added to the process wide pending signal set. The
signal will be delivered to the first thread that unmasks
the signal.
If there is an installed signal handler, it is only invoked
if the chosen thread was not in a sigwait.
In the case that multiple threads are waiting or suspended
on a signal, or multiple threads have the signal unmasked,
we wake up/deliver the signal to the first thread we find.
The above rules still apply.
Reported by: Scott Hess <scott@avantgo.com>
Reviewed by: jb, jasone
1999-12-04 22:55:59 +00:00
|
|
|
*/
|
|
|
|
SCLASS sigset_t _process_sigpending;
|
2000-11-09 05:08:26 +00:00
|
|
|
SCLASS sigset_t _process_sigmask
|
|
|
|
#ifdef GLOBAL_PTHREAD_PRIVATE
|
|
|
|
= { {0, 0, 0, 0} }
|
|
|
|
#endif
|
|
|
|
;
|
1998-04-29 09:59:34 +00:00
|
|
|
|
1999-03-23 05:07:56 +00:00
|
|
|
/*
|
|
|
|
* Scheduling queues:
|
|
|
|
*/
|
|
|
|
SCLASS pq_queue_t _readyq;
|
2000-05-26 02:09:24 +00:00
|
|
|
SCLASS TAILQ_HEAD(, pthread) _waitingq;
|
1999-03-23 05:07:56 +00:00
|
|
|
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
/*
|
|
|
|
* Work queue:
|
|
|
|
*/
|
2000-05-26 02:09:24 +00:00
|
|
|
SCLASS TAILQ_HEAD(, pthread) _workq;
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
|
|
|
|
/* Tracks the number of threads blocked while waiting for a spinlock. */
|
|
|
|
SCLASS volatile int _spinblock_count
|
|
|
|
#ifdef GLOBAL_PTHREAD_PRIVATE
|
|
|
|
= 0
|
|
|
|
#endif
|
|
|
|
;
|
|
|
|
|
2000-10-13 22:12:32 +00:00
|
|
|
/* Used to maintain pending and active signals: */
|
|
|
|
struct sigstatus {
|
|
|
|
int pending; /* Is this a pending signal? */
|
|
|
|
int blocked; /*
|
|
|
|
* A handler is currently active for
|
|
|
|
* this signal; ignore subsequent
|
|
|
|
* signals until the handler is done.
|
|
|
|
*/
|
|
|
|
int signo; /* arg 1 to signal handler */
|
|
|
|
siginfo_t siginfo; /* arg 2 to signal handler */
|
|
|
|
ucontext_t uc; /* arg 3 to signal handler */
|
|
|
|
};
|
|
|
|
|
|
|
|
SCLASS struct sigstatus _thread_sigq[NSIG];
|
|
|
|
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
/* Indicates that the signal queue needs to be checked. */
|
|
|
|
SCLASS volatile int _sigq_check_reqd
|
1999-03-23 05:07:56 +00:00
|
|
|
#ifdef GLOBAL_PTHREAD_PRIVATE
|
|
|
|
= 0
|
|
|
|
#endif
|
|
|
|
;
|
|
|
|
|
|
|
|
/* Thread switch hook. */
|
|
|
|
SCLASS pthread_switch_routine_t _sched_switch_hook
|
|
|
|
#ifdef GLOBAL_PTHREAD_PRIVATE
|
|
|
|
= NULL
|
|
|
|
#endif
|
|
|
|
;
|
|
|
|
|
2000-10-13 22:12:32 +00:00
|
|
|
/*
|
|
|
|
* Declare the kernel scheduler jump buffer and stack:
|
|
|
|
*/
|
|
|
|
SCLASS jmp_buf _thread_kern_sched_jb;
|
|
|
|
|
|
|
|
SCLASS void * _thread_kern_sched_stack
|
|
|
|
#ifdef GLOBAL_PTHREAD_PRIVATE
|
|
|
|
= NULL
|
|
|
|
#endif
|
|
|
|
;
|
|
|
|
|
|
|
|
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
/* Used for _PTHREADS_INVARIANTS checking. */
|
|
|
|
SCLASS int _thread_kern_new_state
|
|
|
|
#ifdef GLOBAL_PTHREAD_PRIVATE
|
|
|
|
= 0
|
|
|
|
#endif
|
|
|
|
;
|
|
|
|
|
1996-01-22 00:23:58 +00:00
|
|
|
/* Undefine the storage class specifier: */
|
|
|
|
#undef SCLASS
|
|
|
|
|
2001-10-26 18:45:02 +00:00
|
|
|
#ifdef _LOCK_DEBUG
|
1998-06-09 23:02:43 +00:00
|
|
|
#define _FD_LOCK(_fd,_type,_ts) _thread_fd_lock_debug(_fd, _type, \
|
|
|
|
_ts, __FILE__, __LINE__)
|
|
|
|
#define _FD_UNLOCK(_fd,_type) _thread_fd_unlock_debug(_fd, _type, \
|
|
|
|
__FILE__, __LINE__)
|
|
|
|
#else
|
|
|
|
#define _FD_LOCK(_fd,_type,_ts) _thread_fd_lock(_fd, _type, _ts)
|
|
|
|
#define _FD_UNLOCK(_fd,_type) _thread_fd_unlock(_fd, _type)
|
|
|
|
#endif
|
|
|
|
|
1996-01-22 00:23:58 +00:00
|
|
|
/*
|
|
|
|
* Function prototype definitions.
|
|
|
|
*/
|
|
|
|
__BEGIN_DECLS
|
|
|
|
char *__ttyname_basic(int);
|
|
|
|
char *__ttyname_r_basic(int, char *, size_t);
|
|
|
|
char *ttyname_r(int, char *, size_t);
|
2000-10-13 22:12:32 +00:00
|
|
|
void _cond_wait_backout(pthread_t);
|
|
|
|
void _fd_lock_backout(pthread_t);
|
1998-04-29 09:59:34 +00:00
|
|
|
int _find_thread(pthread_t);
|
2001-01-24 13:03:38 +00:00
|
|
|
struct pthread *_get_curthread(void);
|
|
|
|
void _set_curthread(struct pthread *);
|
2001-07-20 04:23:11 +00:00
|
|
|
void *_thread_stack_alloc(size_t, size_t);
|
|
|
|
void _thread_stack_free(void *, size_t, size_t);
|
1996-01-22 00:23:58 +00:00
|
|
|
int _thread_create(pthread_t *,const pthread_attr_t *,void *(*start_routine)(void *),void *,pthread_t);
|
1999-03-23 05:07:56 +00:00
|
|
|
int _mutex_cv_lock(pthread_mutex_t *);
|
|
|
|
int _mutex_cv_unlock(pthread_mutex_t *);
|
2000-10-13 22:12:32 +00:00
|
|
|
void _mutex_lock_backout(pthread_t);
|
1999-11-28 05:38:13 +00:00
|
|
|
void _mutex_notify_priochange(pthread_t);
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
int _mutex_reinit(pthread_mutex_t *);
|
1999-11-28 05:38:13 +00:00
|
|
|
void _mutex_unlock_private(pthread_t);
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
int _cond_reinit(pthread_cond_t *);
|
|
|
|
int _pq_alloc(struct pq_queue *, int, int);
|
|
|
|
int _pq_init(struct pq_queue *);
|
1999-03-23 05:07:56 +00:00
|
|
|
void _pq_remove(struct pq_queue *pq, struct pthread *);
|
|
|
|
void _pq_insert_head(struct pq_queue *pq, struct pthread *);
|
|
|
|
void _pq_insert_tail(struct pq_queue *pq, struct pthread *);
|
|
|
|
struct pthread *_pq_first(struct pq_queue *pq);
|
2001-01-24 13:03:38 +00:00
|
|
|
void *_pthread_getspecific(pthread_key_t);
|
|
|
|
int _pthread_key_create(pthread_key_t *, void (*) (void *));
|
|
|
|
int _pthread_key_delete(pthread_key_t);
|
|
|
|
int _pthread_mutex_destroy(pthread_mutex_t *);
|
|
|
|
int _pthread_mutex_init(pthread_mutex_t *, const pthread_mutexattr_t *);
|
|
|
|
int _pthread_mutex_lock(pthread_mutex_t *);
|
|
|
|
int _pthread_mutex_trylock(pthread_mutex_t *);
|
|
|
|
int _pthread_mutex_unlock(pthread_mutex_t *);
|
|
|
|
int _pthread_mutexattr_init(pthread_mutexattr_t *);
|
|
|
|
int _pthread_mutexattr_destroy(pthread_mutexattr_t *);
|
|
|
|
int _pthread_mutexattr_settype(pthread_mutexattr_t *, int);
|
|
|
|
int _pthread_once(pthread_once_t *, void (*) (void));
|
2001-02-11 22:07:32 +00:00
|
|
|
pthread_t _pthread_self(void);
|
2001-01-24 13:03:38 +00:00
|
|
|
int _pthread_setspecific(pthread_key_t, const void *);
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
void _waitq_insert(pthread_t pthread);
|
|
|
|
void _waitq_remove(pthread_t pthread);
|
2000-10-13 22:12:32 +00:00
|
|
|
#if defined(_PTHREADS_INVARIANTS)
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
void _waitq_setactive(void);
|
|
|
|
void _waitq_clearactive(void);
|
|
|
|
#endif
|
1996-01-22 00:23:58 +00:00
|
|
|
void _thread_exit(char *, int, char *);
|
1999-11-28 05:38:13 +00:00
|
|
|
void _thread_exit_cleanup(void);
|
2002-08-29 23:06:07 +00:00
|
|
|
int _thread_fd_getflags(int);
|
|
|
|
int _thread_fd_lock(int, int, struct timespec *);
|
|
|
|
int _thread_fd_lock_debug(int, int, struct timespec *,char *fname,int lineno);
|
|
|
|
void _thread_fd_setflags(int, int);
|
|
|
|
int _thread_fd_table_init(int fd);
|
1996-01-22 00:23:58 +00:00
|
|
|
void _thread_fd_unlock(int, int);
|
1998-06-09 23:02:43 +00:00
|
|
|
void _thread_fd_unlock_debug(int, int, char *, int);
|
1999-11-28 05:38:13 +00:00
|
|
|
void _thread_fd_unlock_owned(pthread_t);
|
1996-01-22 00:23:58 +00:00
|
|
|
void *_thread_cleanup(pthread_t);
|
|
|
|
void _thread_cleanupspecific(void);
|
|
|
|
void _thread_dump_info(void);
|
|
|
|
void _thread_init(void);
|
1999-09-29 15:18:46 +00:00
|
|
|
void _thread_kern_sched(ucontext_t *);
|
2000-10-13 22:12:32 +00:00
|
|
|
void _thread_kern_scheduler(void);
|
2000-11-09 05:08:26 +00:00
|
|
|
void _thread_kern_sched_frame(struct pthread_signal_frame *psf);
|
2000-10-13 22:12:32 +00:00
|
|
|
void _thread_kern_sched_sig(void);
|
|
|
|
void _thread_kern_sched_state(enum pthread_state, char *fname, int lineno);
|
1998-11-15 09:58:26 +00:00
|
|
|
void _thread_kern_sched_state_unlock(enum pthread_state state,
|
|
|
|
spinlock_t *lock, char *fname, int lineno);
|
2000-08-07 16:51:56 +00:00
|
|
|
void _thread_kern_set_timeout(const struct timespec *);
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
void _thread_kern_sig_defer(void);
|
|
|
|
void _thread_kern_sig_undefer(void);
|
2000-10-13 22:12:32 +00:00
|
|
|
void _thread_sig_handler(int, siginfo_t *, ucontext_t *);
|
2002-02-09 19:58:41 +00:00
|
|
|
void _thread_sig_check_pending(struct pthread *pthread);
|
2000-10-13 22:12:32 +00:00
|
|
|
void _thread_sig_handle_pending(void);
|
2002-02-09 19:58:41 +00:00
|
|
|
void _thread_sig_send(struct pthread *pthread, int sig);
|
2000-10-13 22:12:32 +00:00
|
|
|
void _thread_sig_wrapper(void);
|
2002-02-09 19:58:41 +00:00
|
|
|
void _thread_sigframe_restore(struct pthread *thread,
|
|
|
|
struct pthread_signal_frame *psf);
|
1996-01-22 00:23:58 +00:00
|
|
|
void _thread_start(void);
|
2000-10-13 22:12:32 +00:00
|
|
|
void _thread_seterrno(pthread_t, int);
|
1998-09-30 06:22:07 +00:00
|
|
|
pthread_addr_t _thread_gc(pthread_addr_t);
|
1999-11-28 05:38:13 +00:00
|
|
|
void _thread_enter_cancellation_point(void);
|
|
|
|
void _thread_leave_cancellation_point(void);
|
|
|
|
void _thread_cancellation_point(void);
|
1996-01-22 00:23:58 +00:00
|
|
|
|
2001-10-26 18:45:02 +00:00
|
|
|
/* #include <sys/acl.h> */
|
|
|
|
#ifdef _SYS_ACL_H
|
|
|
|
int __sys___acl_aclcheck_fd(int, acl_type_t, struct acl *);
|
|
|
|
int __sys___acl_delete_fd(int, acl_type_t);
|
|
|
|
int __sys___acl_get_fd(int, acl_type_t, struct acl *);
|
|
|
|
int __sys___acl_set_fd(int, acl_type_t, struct acl *);
|
|
|
|
#endif
|
|
|
|
|
2001-01-29 03:24:23 +00:00
|
|
|
/* #include <sys/aio.h> */
|
|
|
|
#ifdef _SYS_AIO_H_
|
2001-01-29 18:59:53 +00:00
|
|
|
int __sys_aio_suspend(const struct aiocb * const[], int, const struct timespec *);
|
2001-01-24 13:03:38 +00:00
|
|
|
#endif
|
|
|
|
|
2001-10-26 18:45:02 +00:00
|
|
|
/* #include <sys/event.h> */
|
|
|
|
#ifdef _SYS_EVENT_H_
|
|
|
|
int __sys_kevent(int, const struct kevent *, int, struct kevent *,
|
|
|
|
int, const struct timespec *);
|
1996-01-22 00:23:58 +00:00
|
|
|
#endif
|
|
|
|
|
2001-10-26 18:45:02 +00:00
|
|
|
/* #include <sys/ioctl.h> */
|
|
|
|
#ifdef _SYS_IOCTL_H_
|
|
|
|
int __sys_ioctl(int, unsigned long, ...);
|
1996-01-22 00:23:58 +00:00
|
|
|
#endif
|
|
|
|
|
2001-10-26 18:45:02 +00:00
|
|
|
/* #include <sys/mman.h> */
|
|
|
|
#ifdef _SYS_MMAN_H_
|
|
|
|
int __sys_msync(void *, size_t, int);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* #include <sys/mount.h> */
|
|
|
|
#ifdef _SYS_MOUNT_H_
|
|
|
|
int __sys_fstatfs(int, struct statfs *);
|
1996-01-22 00:23:58 +00:00
|
|
|
#endif
|
|
|
|
|
2001-01-24 13:03:38 +00:00
|
|
|
/* #include <sys/socket.h> */
|
2001-10-26 18:45:02 +00:00
|
|
|
#ifdef _SYS_SOCKET_H_
|
2001-10-26 17:46:36 +00:00
|
|
|
int __sys_accept(int, struct sockaddr *, socklen_t *);
|
|
|
|
int __sys_bind(int, const struct sockaddr *, socklen_t);
|
|
|
|
int __sys_connect(int, const struct sockaddr *, socklen_t);
|
|
|
|
int __sys_getpeername(int, struct sockaddr *, socklen_t *);
|
|
|
|
int __sys_getsockname(int, struct sockaddr *, socklen_t *);
|
|
|
|
int __sys_getsockopt(int, int, int, void *, socklen_t *);
|
2001-10-26 18:45:02 +00:00
|
|
|
int __sys_listen(int, int);
|
2001-10-26 17:46:36 +00:00
|
|
|
ssize_t __sys_recvfrom(int, void *, size_t, int, struct sockaddr *, socklen_t *);
|
2001-10-26 18:45:02 +00:00
|
|
|
ssize_t __sys_recvmsg(int, struct msghdr *, int);
|
2001-01-24 13:03:38 +00:00
|
|
|
int __sys_sendfile(int, int, off_t, size_t, struct sf_hdtr *, off_t *, int);
|
2001-10-26 18:45:02 +00:00
|
|
|
ssize_t __sys_sendmsg(int, const struct msghdr *, int);
|
2001-10-26 17:46:36 +00:00
|
|
|
ssize_t __sys_sendto(int, const void *,size_t, int, const struct sockaddr *, socklen_t);
|
2001-10-26 18:45:02 +00:00
|
|
|
int __sys_setsockopt(int, int, int, const void *, socklen_t);
|
|
|
|
int __sys_shutdown(int, int);
|
|
|
|
int __sys_socket(int, int, int);
|
|
|
|
int __sys_socketpair(int, int, int, int *);
|
1996-01-22 00:23:58 +00:00
|
|
|
#endif
|
|
|
|
|
2001-10-26 18:45:02 +00:00
|
|
|
/* #include <sys/stat.h> */
|
|
|
|
#ifdef _SYS_STAT_H_
|
|
|
|
int __sys_fchflags(int, u_long);
|
|
|
|
int __sys_fchmod(int, mode_t);
|
|
|
|
int __sys_fstat(int, struct stat *);
|
1996-01-22 00:23:58 +00:00
|
|
|
#endif
|
|
|
|
|
2001-10-26 18:45:02 +00:00
|
|
|
/* #include <sys/uio.h> */
|
|
|
|
#ifdef _SYS_UIO_H_
|
|
|
|
ssize_t __sys_readv(int, const struct iovec *, int);
|
|
|
|
ssize_t __sys_writev(int, const struct iovec *, int);
|
1996-01-22 00:23:58 +00:00
|
|
|
#endif
|
|
|
|
|
2001-10-26 18:45:02 +00:00
|
|
|
/* #include <sys/wait.h> */
|
|
|
|
#ifdef WNOHANG
|
|
|
|
pid_t __sys_wait4(pid_t, int *, int, struct rusage *);
|
1996-01-22 00:23:58 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* #include <dirent.h> */
|
2001-10-26 18:45:02 +00:00
|
|
|
#ifdef _DIRENT_H_
|
|
|
|
int __sys_getdirentries(int, char *, int, long *);
|
1996-01-22 00:23:58 +00:00
|
|
|
#endif
|
|
|
|
|
2001-10-26 18:45:02 +00:00
|
|
|
/* #include <fcntl.h> */
|
|
|
|
#ifdef _SYS_FCNTL_H_
|
|
|
|
int __sys_fcntl(int, int, ...);
|
|
|
|
int __sys_flock(int, int);
|
|
|
|
int __sys_open(const char *, int, ...);
|
1996-01-22 00:23:58 +00:00
|
|
|
#endif
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
|
|
|
|
/* #include <poll.h> */
|
|
|
|
#ifdef _SYS_POLL_H_
|
2001-10-26 18:45:02 +00:00
|
|
|
int __sys_poll(struct pollfd *, unsigned, int);
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
#endif
|
2000-01-19 07:04:50 +00:00
|
|
|
|
2001-10-26 18:45:02 +00:00
|
|
|
/* #include <signal.h> */
|
|
|
|
#ifdef _SIGNAL_H_
|
|
|
|
int __sys_sigaction(int, const struct sigaction *, struct sigaction *);
|
|
|
|
int __sys_sigprocmask(int, const sigset_t *, sigset_t *);
|
|
|
|
int __sys_sigreturn(ucontext_t *);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* #include <unistd.h> */
|
|
|
|
#ifdef _UNISTD_H_
|
|
|
|
int __sys_close(int);
|
|
|
|
int __sys_dup(int);
|
|
|
|
int __sys_dup2(int, int);
|
|
|
|
int __sys_execve(const char *, char * const *, char * const *);
|
|
|
|
void __sys_exit(int);
|
|
|
|
int __sys_fchown(int, uid_t, gid_t);
|
|
|
|
pid_t __sys_fork(void);
|
|
|
|
long __sys_fpathconf(int, int);
|
|
|
|
int __sys_fsync(int);
|
|
|
|
int __sys_pipe(int *);
|
|
|
|
ssize_t __sys_read(int, void *, size_t);
|
|
|
|
ssize_t __sys_write(int, const void *, size_t);
|
2000-01-19 07:04:50 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* #include <setjmp.h> */
|
|
|
|
#ifdef _SETJMP_H_
|
2000-01-20 21:53:59 +00:00
|
|
|
extern void __siglongjmp(sigjmp_buf, int) __dead2;
|
|
|
|
extern void __longjmp(jmp_buf, int) __dead2;
|
|
|
|
extern void ___longjmp(jmp_buf, int) __dead2;
|
2000-01-19 07:04:50 +00:00
|
|
|
#endif
|
1996-01-22 00:23:58 +00:00
|
|
|
__END_DECLS
|
|
|
|
|
|
|
|
#endif /* !_PTHREAD_PRIVATE_H */
|