diff options
author | Marco S Hyman <marc@cvs.openbsd.org> | 2003-01-31 04:46:18 +0000 |
---|---|---|
committer | Marco S Hyman <marc@cvs.openbsd.org> | 2003-01-31 04:46:18 +0000 |
commit | 68795d4df128d80b54c55c9e7769c34c96270983 (patch) | |
tree | 1182fb066f0927d28dfb77b60c677da68c8f63f5 | |
parent | 132b289627ab477bb921ce53d385e7900cdcd50f (diff) |
Create a siginfo_t for thread-to-thread kill.
Clean up (compiler warning elimination). Compile check options added
but commented out as they have not been checked on all architectures, yet.
-rw-r--r-- | lib/libpthread/Makefile | 4 | ||||
-rw-r--r-- | lib/libpthread/arch/sparc/uthread_machdep.c | 10 | ||||
-rw-r--r-- | lib/libpthread/include/spinlock.h | 8 | ||||
-rw-r--r-- | lib/libpthread/sys/uthread_error.c | 5 | ||||
-rw-r--r-- | lib/libpthread/uthread/pthread_private.h | 30 | ||||
-rw-r--r-- | lib/libpthread/uthread/uthread_autoinit.c | 40 | ||||
-rw-r--r-- | lib/libpthread/uthread/uthread_file.c | 4 | ||||
-rw-r--r-- | lib/libpthread/uthread/uthread_gc.c | 4 | ||||
-rw-r--r-- | lib/libpthread/uthread/uthread_info_openbsd.c | 13 | ||||
-rw-r--r-- | lib/libpthread/uthread/uthread_init.c | 6 | ||||
-rw-r--r-- | lib/libpthread/uthread/uthread_kern.c | 11 | ||||
-rw-r--r-- | lib/libpthread/uthread/uthread_kill.c | 31 | ||||
-rw-r--r-- | lib/libpthread/uthread/uthread_mutex.c | 85 | ||||
-rw-r--r-- | lib/libpthread/uthread/uthread_sig.c | 15 | ||||
-rw-r--r-- | lib/libpthread/uthread/uthread_sigaction.c | 4 | ||||
-rw-r--r-- | lib/libpthread/uthread/uthread_sigwait.c | 4 | ||||
-rw-r--r-- | lib/libpthread/uthread/uthread_spinlock.c | 4 | ||||
-rw-r--r-- | lib/libpthread/uthread/uthread_write.c | 4 | ||||
-rw-r--r-- | lib/libpthread/uthread/uthread_writev.c | 10 |
19 files changed, 113 insertions, 179 deletions
diff --git a/lib/libpthread/Makefile b/lib/libpthread/Makefile index 7bd7077e0af..bcccd6f9d58 100644 --- a/lib/libpthread/Makefile +++ b/lib/libpthread/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.17 2003/01/20 18:12:11 marc Exp $ +# $OpenBSD: Makefile,v 1.18 2003/01/31 04:46:16 marc Exp $ # # The pthread library is formed from the FreeBSD uthread sources of @@ -11,6 +11,8 @@ LIBCSRCDIR= ${.CURDIR}/../libc LIB= pthread LINTFLAGS= -z CFLAGS+= -DPTHREAD_KERNEL -D_POSIX_THREADS -D_THREAD_SAFE -Wall +#CFLAGS+= -Wpointer-arith -Wwrite-strings -Wstrict-prototypes +#CFLAGS+= -Wmissing-prototypes -Wsign-compare -Werror CFLAGS+= -I${SRCDIR}/uthread CFLAGS+= -I${SRCDIR}/include CFLAGS+= -I${LIBCSRCDIR}/include diff --git a/lib/libpthread/arch/sparc/uthread_machdep.c b/lib/libpthread/arch/sparc/uthread_machdep.c index 006fb9f4aa5..f7599ef4636 100644 --- a/lib/libpthread/arch/sparc/uthread_machdep.c +++ b/lib/libpthread/arch/sparc/uthread_machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_machdep.c,v 1.2 2003/01/26 20:24:36 jason Exp $ */ +/* $OpenBSD: uthread_machdep.c,v 1.3 2003/01/31 04:46:16 marc Exp $ */ /* * Machine-dependent thread state functions for OpenBSD/sparc. @@ -9,6 +9,9 @@ #include <pthread.h> #include "pthread_private.h" +extern void _thread_machdep_fpsave(u_int32_t *, u_int64_t *); +extern void _thread_machdep_fprestore(u_int32_t *, u_int64_t *); + /* * Given a stack and an entry function, initialise a state * structure that can be later switched to. @@ -35,13 +38,12 @@ void _thread_machdep_save_float_state(statep) struct _machdep_state* statep; { - u_int32_t zero = 0; - - _thread_machdep_fpsave(&statep->fs_csr, &statep->fs_regs[0], &zero); + _thread_machdep_fpsave(&statep->fs_csr, &statep->fs_regs[0]); } void _thread_machdep_restore_float_state(statep) struct _machdep_state* statep; { + _thread_machdep_fprestore(&statep->fs_csr, &statep->fs_regs[0]); } diff --git a/lib/libpthread/include/spinlock.h b/lib/libpthread/include/spinlock.h index 8c87e963de1..717072115b0 100644 --- a/lib/libpthread/include/spinlock.h +++ b/lib/libpthread/include/spinlock.h @@ -29,8 +29,8 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: spinlock.h,v 1.7 2002/02/16 21:27:25 millert Exp $ - * $OpenBSD: spinlock.h,v 1.7 2002/02/16 21:27:25 millert Exp $ + * $Id: spinlock.h,v 1.8 2003/01/31 04:46:17 marc Exp $ + * $OpenBSD: spinlock.h,v 1.8 2003/01/31 04:46:17 marc Exp $ * * Lock definitions used in both libc and libpthread. * @@ -48,7 +48,7 @@ typedef volatile struct { _spinlock_lock_t access_lock; void * lock_owner; - char * fname; + const char * fname; int lineno; } spinlock_t; @@ -68,7 +68,7 @@ typedef volatile struct { */ __BEGIN_DECLS void _spinlock(spinlock_t *); -void _spinlock_debug(spinlock_t *, char *, int); +void _spinlock_debug(spinlock_t *, const char *, int); /* lock() functions return 0 if lock was acquired. */ /* is_locked functions() return 1 if lock is locked. */ diff --git a/lib/libpthread/sys/uthread_error.c b/lib/libpthread/sys/uthread_error.c index 08740ed92ff..739d3abf347 100644 --- a/lib/libpthread/sys/uthread_error.c +++ b/lib/libpthread/sys/uthread_error.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_error.c,v 1.2 1999/11/25 07:01:30 d Exp $ */ +/* $OpenBSD: uthread_error.c,v 1.3 2003/01/31 04:46:17 marc Exp $ */ /* * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. * Copyright (c) 1994 by Chris Provenzano, proven@mit.edu @@ -39,7 +39,8 @@ #include "pthread_private.h" extern int errno; -int * __error() +int * +__error(void) { int *p_errno; if (_thread_run == _thread_initial) { diff --git a/lib/libpthread/uthread/pthread_private.h b/lib/libpthread/uthread/pthread_private.h index cae2335ef0d..639ab7d916f 100644 --- a/lib/libpthread/uthread/pthread_private.h +++ b/lib/libpthread/uthread/pthread_private.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pthread_private.h,v 1.42 2003/01/27 22:22:30 marc Exp $ */ +/* $OpenBSD: pthread_private.h,v 1.43 2003/01/31 04:46:17 marc Exp $ */ /* * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>. * All rights reserved. @@ -341,7 +341,7 @@ struct sem { */ struct pthread_cleanup { struct pthread_cleanup *next; - void (*routine) (); + void (*routine)(void*); void *routine_arg; }; @@ -353,7 +353,7 @@ struct pthread_attr { int suspend; int flags; void *arg_attr; - void (*cleanup_attr) (); + void (*cleanup_attr)(void*); void *stackaddr_attr; size_t stacksize_attr; size_t guardsize_attr; @@ -442,7 +442,7 @@ struct pthread_key { spinlock_t lock; volatile int allocated; volatile int count; - void (*destructor) (); + void (*destructor)(void*); }; struct pthread_rwlockattr { @@ -523,9 +523,9 @@ union pthread_wait_data { pthread_cond_t cond; 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.*/ + short fd; /* Used when thread waiting on fd */ + short branch; /* Line number, for debugging. */ + const char *fname; /* Source file name for debugging.*/ } fd; FILE *fp; struct pthread_poll_data *poll_data; @@ -776,7 +776,7 @@ struct pthread { /* Cleanup handlers Link List */ struct pthread_cleanup *cleanup; - char *fname; /* Ptr to source file name */ + const char *fname; /* Ptr to source file name */ int lineno; /* Source line number. */ }; @@ -1014,6 +1014,7 @@ SCLASS volatile int _spinblock_count /* Used to maintain pending and active signals: */ struct sigstatus { + spinlock_t lock; /* structure access lock */ int pending; /* Is this a pending signal? */ siginfo_t siginfo; /* arg 2 to signal handler */ }; @@ -1060,11 +1061,13 @@ SCLASS int _thread_kern_new_state * Function prototype definitions. */ __BEGIN_DECLS +int *__error(void); int _find_thread(pthread_t); struct pthread *_get_curthread(void); void _set_curthread(struct pthread *); int _thread_create(pthread_t *, const pthread_attr_t *, void *(*start_routine)(void *), void *,pthread_t); +void _dispatch_signal(int, struct sigcontext *); void _dispatch_signals(struct sigcontext *); void _thread_signal(pthread_t, int); int _mutex_cv_lock(pthread_mutex_t *); @@ -1092,12 +1095,13 @@ void _thread_dump_data(const void *, int); void _thread_dump_info(void); void _thread_init(void); void _thread_kern_sched(struct sigcontext *); -void _thread_kern_sched_state(enum pthread_state,char *fname,int lineno); -void _thread_kern_sched_state_unlock(enum pthread_state state, - spinlock_t *lock, char *fname, int lineno); +void _thread_kern_sched_state(enum pthread_state, const char *, int); +void _thread_kern_sched_state_unlock(enum pthread_state, spinlock_t *, + const char *, int); void _thread_kern_set_timeout(const struct timespec *); void _thread_kern_sig_defer(void); void _thread_kern_sig_undefer(void); +void _thread_kill_siginfo(int); void _thread_sig_handler(int, siginfo_t *, struct sigcontext *); int _thread_sig_handle(int, struct sigcontext *); void _thread_sig_init(void); @@ -1105,6 +1109,8 @@ void _thread_start(void); void _thread_start_sig_handler(void); void _thread_seterrno(pthread_t,int); int _thread_fd_table_init(int fd); +void _thread_fd_unlock_owned(pthread_t); +void _thread_fd_unlock_thread(struct pthread *, int, int, const char *, int); pthread_addr_t _thread_gc(pthread_addr_t); void _thread_enter_cancellation_point(void); void _thread_leave_cancellation_point(void); @@ -1119,6 +1125,8 @@ void _thread_stack_free(struct stack *); #ifdef _USER_SIGNAL_H int _thread_sys_kill(pid_t, int); int _thread_sys_sigaction(int, const struct sigaction *, struct sigaction *); +int _thread_sys_sigblock(int); +int _thread_sys_sigsetmask(int); int _thread_sys_sigpending(sigset_t *); int _thread_sys_sigprocmask(int, const sigset_t *, sigset_t *); int _thread_sys_sigsuspend(const sigset_t *); diff --git a/lib/libpthread/uthread/uthread_autoinit.c b/lib/libpthread/uthread/uthread_autoinit.c index 5753d434c7f..1601d2098c9 100644 --- a/lib/libpthread/uthread/uthread_autoinit.c +++ b/lib/libpthread/uthread/uthread_autoinit.c @@ -1,23 +1,14 @@ /* * David Leonard, 1998. Public Domain. <david.leonard@csee.uq.edu.au> * - * $OpenBSD: uthread_autoinit.c,v 1.10 2002/02/16 21:27:25 millert Exp $ + * $OpenBSD: uthread_autoinit.c,v 1.11 2003/01/31 04:46:17 marc Exp $ */ + #include <stdio.h> #include <pthread.h> #include "pthread_private.h" -__BEGIN_DECLS -extern void _thread_init(void); -__END_DECLS - -#ifdef DEBUG -#define init_debug(m) stderr_debug( "[init method: " m "]\n") -#else -#define init_debug(m) /* nothing */ -#endif - /* * Use C++'s static instance constructor to initialise threads. */ @@ -25,7 +16,6 @@ __END_DECLS class Init { public: Init() { - init_debug("C++"); _thread_init(); } }; @@ -33,31 +23,17 @@ Init _thread_initialiser; #endif /* C++ */ /* - * The a.out ld.so dynamic linker calls the function - * at symbol ".init" if it exists, just after linkage. + * This construct places the function in the __CTOR_LIST__ entry in the + * object, and later the collect2 stage of linkage will inform __main (from + * libgcc.a) to call it. */ -extern void _thread_dot_init(void) asm(".init"); -void -_thread_dot_init() -{ - init_debug("a.out .init"); - _thread_init(); -} +#if defined(__GNUC__) +extern void _thread_init_constructor(void) __attribute__((constructor)); +extern void _GLOBAL_$I$_thread_init_constructor(void); -/* - * A GNU C installation may know how to automatically run - * constructors for other architectures. (It doesn't matter if - * we initialise multiple times.) This construct places - * the function in the __CTOR_LIST__ entry in the object, and later - * the collect2 stage of linkage will inform __main (from libgcc.a) - * to call it. - */ -#if defined(__GNUC__) /* && defined(notyet) */ /* internal compiler error??? */ -void _thread_init_constructor(void) __attribute__((constructor)); void _thread_init_constructor() { - init_debug("GNU constructor"); _thread_init(); } #endif /* GNU C */ diff --git a/lib/libpthread/uthread/uthread_file.c b/lib/libpthread/uthread/uthread_file.c index 73f8cda30f5..b50174c0d2b 100644 --- a/lib/libpthread/uthread/uthread_file.c +++ b/lib/libpthread/uthread/uthread_file.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_file.c,v 1.9 2002/11/07 03:51:21 marc Exp $ */ +/* $OpenBSD: uthread_file.c,v 1.10 2003/01/31 04:46:17 marc Exp $ */ /* * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. * All rights reserved. @@ -239,7 +239,7 @@ _flockfile_debug(FILE * fp, char *fname, int lineno) void flockfile(FILE * fp) { - _flockfile_debug(fp, "?", 1); + _flockfile_debug(fp, (char *) "?", 1); return; } diff --git a/lib/libpthread/uthread/uthread_gc.c b/lib/libpthread/uthread/uthread_gc.c index 956633e7fe4..1fb1e56be4a 100644 --- a/lib/libpthread/uthread/uthread_gc.c +++ b/lib/libpthread/uthread/uthread_gc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_gc.c,v 1.11 2001/12/11 00:19:47 fgsch Exp $ */ +/* $OpenBSD: uthread_gc.c,v 1.12 2003/01/31 04:46:17 marc Exp $ */ /* * Copyright (c) 1998 John Birrell <jb@cimlogic.com.au> * All rights reserved. @@ -69,7 +69,7 @@ _thread_gc(pthread_addr_t arg) f_debug = (getenv("LIBC_R_DEBUG") != NULL); /* Set the name of this thread. */ - pthread_set_name_np(curthread,"GC"); + pthread_set_name_np(curthread, (char *)"GC"); while (!f_done) { /* Check if debugging this application. */ diff --git a/lib/libpthread/uthread/uthread_info_openbsd.c b/lib/libpthread/uthread/uthread_info_openbsd.c index 0b7881d6477..54ccd6127ba 100644 --- a/lib/libpthread/uthread/uthread_info_openbsd.c +++ b/lib/libpthread/uthread/uthread_info_openbsd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_info_openbsd.c,v 1.7 2002/12/11 23:21:19 marc Exp $ */ +/* $OpenBSD: uthread_info_openbsd.c,v 1.8 2003/01/31 04:46:17 marc Exp $ */ /* * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> @@ -48,7 +48,7 @@ int _thread_dump_verbose = 0; struct s_thread_info { enum pthread_state state; - char *name; + const char *name; }; /* Static variables: */ @@ -96,15 +96,12 @@ truncname(const char *name, int maxlen) } static void -_thread_dump_entry(pthread, fd, verbose) - pthread_t pthread; - int fd; - int verbose; +_thread_dump_entry(pthread_t pthread, int fd, int verbose) { const char *state; char s[512]; char location[30]; - int j; + unsigned int j; /* Find last known file:line checkpoint: */ if (pthread->fname && pthread->state != PS_RUNNING) @@ -440,7 +437,7 @@ _thread_dump_data(const void *addr, int len) len = 0; memset(data, ' ', DUMP_BUFLEN); } - addr += 8; + (char *) addr += 8; sprintf( data, "%18p: ", d ); while (count--) { diff --git a/lib/libpthread/uthread/uthread_init.c b/lib/libpthread/uthread/uthread_init.c index 4215530506a..db517e6d97f 100644 --- a/lib/libpthread/uthread/uthread_init.c +++ b/lib/libpthread/uthread/uthread_init.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_init.c,v 1.26 2003/01/20 19:43:51 marc Exp $ */ +/* $OpenBSD: uthread_init.c,v 1.27 2003/01/31 04:46:17 marc Exp $ */ /* * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> * All rights reserved. @@ -276,7 +276,7 @@ _thread_init(void) _thread_initial->last_active = (long) _sched_ticks; /* Give it a useful name */ - pthread_set_name_np(_thread_initial, "main"); + pthread_set_name_np(_thread_initial, (char *)"main"); /* Initialise the rest of the fields: */ _thread_initial->poll_data.nfds = 0; @@ -296,7 +296,7 @@ _thread_init(void) /* Initialise the global signal action structure: */ sigfillset(&act.sa_mask); - act.sa_handler = (void (*) ()) _thread_sig_handler; + act.sa_handler = (void (*) (int)) _thread_sig_handler; act.sa_flags = SA_SIGINFO; /* Clear pending signals for the process: */ diff --git a/lib/libpthread/uthread/uthread_kern.c b/lib/libpthread/uthread/uthread_kern.c index d72e7b5ed9e..5a9e7ccc3c3 100644 --- a/lib/libpthread/uthread/uthread_kern.c +++ b/lib/libpthread/uthread/uthread_kern.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_kern.c,v 1.25 2003/01/27 22:22:30 marc Exp $ */ +/* $OpenBSD: uthread_kern.c,v 1.26 2003/01/31 04:46:17 marc Exp $ */ /* * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> * All rights reserved. @@ -59,7 +59,7 @@ void _dequeue_signals(void); inline void _thread_run_switch_hook(pthread_t, pthread_t); /* Static variables: */ -static int last_tick = 0; +static unsigned int last_tick = 0; void _thread_kern_sched(struct sigcontext * scp) @@ -513,7 +513,8 @@ _thread_kern_sched(struct sigcontext * scp) } void -_thread_kern_sched_state(enum pthread_state state, char *fname, int lineno) +_thread_kern_sched_state(enum pthread_state state, const char *fname, + int lineno) { struct pthread *curthread = _get_curthread(); @@ -540,8 +541,8 @@ _thread_kern_sched_state(enum pthread_state state, char *fname, int lineno) } void -_thread_kern_sched_state_unlock(enum pthread_state state, - spinlock_t *lock, char *fname, int lineno) +_thread_kern_sched_state_unlock(enum pthread_state state, spinlock_t *lock, + const char *fname, int lineno) { struct pthread *curthread = _get_curthread(); diff --git a/lib/libpthread/uthread/uthread_kill.c b/lib/libpthread/uthread/uthread_kill.c index 9e94a7f0ee4..e39c3320e2f 100644 --- a/lib/libpthread/uthread/uthread_kill.c +++ b/lib/libpthread/uthread/uthread_kill.c @@ -1,15 +1,38 @@ -/* $OpenBSD: uthread_kill.c,v 1.9 2003/01/27 22:22:30 marc Exp $ */ +/* $OpenBSD: uthread_kill.c,v 1.10 2003/01/31 04:46:17 marc Exp $ */ /* PUBLIC_DOMAIN <marc@snafu.org> */ #include <errno.h> #include <signal.h> +#include <string.h> +#include <unistd.h> #ifdef _THREAD_SAFE #include <pthread.h> + #include "pthread_private.h" /* + * Fake up a minimal siginfo_t for the given signal unless one is already + * pending. The signal number is assumed to be valid. + */ +void +_thread_kill_siginfo(int sig) +{ + struct sigstatus *ss = &_thread_sigq[sig - 1]; + + _SPINLOCK(&ss->lock); + if (ss->pending == 0) { + ss->pending = 1; + memset(&ss->siginfo, 0, sizeof ss->siginfo); + ss->siginfo.si_signo = sig; + ss->siginfo.si_code = SI_USER; + ss->siginfo.si_errno = errno; + ss->siginfo.si_pid = getpid(); + } + _SPINUNLOCK(&ss->lock); +} + +/* * Validate the signal number and thread. If valid process the signal. - * ;;; need to fake up a siginfo_t and put it in the queue for this signal. */ int pthread_kill(pthread_t pthread, int sig) @@ -24,8 +47,10 @@ pthread_kill(pthread_t pthread, int sig) sigismember(pthread->data.sigwait, sig)) { PTHREAD_NEW_STATE(pthread,PS_RUNNING); pthread->signo = sig; - } else + } else { + _thread_kill_siginfo(sig); _thread_signal(pthread,sig); + } } } } else diff --git a/lib/libpthread/uthread/uthread_mutex.c b/lib/libpthread/uthread/uthread_mutex.c index 5845cf01a6b..14733506ce1 100644 --- a/lib/libpthread/uthread/uthread_mutex.c +++ b/lib/libpthread/uthread/uthread_mutex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_mutex.c,v 1.16 2003/01/27 22:22:30 marc Exp $ */ +/* $OpenBSD: uthread_mutex.c,v 1.17 2003/01/31 04:46:17 marc Exp $ */ /* * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. * All rights reserved. @@ -76,10 +76,6 @@ static inline void mutex_queue_enq(pthread_mutex_t, pthread_t); static spinlock_t static_init_lock = _SPINLOCK_INITIALIZER; -static struct pthread_mutex_attr static_mutex_attr = - PTHREAD_MUTEXATTR_STATIC_INITIALIZER; -static pthread_mutexattr_t static_mattr = &static_mutex_attr; - /* Reinitialize a mutex to defaults. */ int _mutex_reinit(pthread_mutex_t * mutex) @@ -268,23 +264,6 @@ init_static(pthread_mutex_t *mutex) } static int -init_static_private(pthread_mutex_t *mutex) -{ - int ret; - - _SPINLOCK(&static_init_lock); - - if (*mutex == NULL) - ret = pthread_mutex_init(mutex, &static_mattr); - else - ret = 0; - - _SPINUNLOCK(&static_init_lock); - - return(ret); -} - -static int mutex_trylock_common(pthread_mutex_t *mutex) { struct pthread *curthread = _get_curthread(); @@ -435,24 +414,6 @@ pthread_mutex_trylock(pthread_mutex_t *mutex) return (ret); } -int -_pthread_mutex_trylock(pthread_mutex_t *mutex) -{ - int ret = 0; - - if (mutex == NULL) - ret = EINVAL; - - /* - * If the mutex is statically initialized, perform the dynamic - * initialization marking the mutex private (delete safe): - */ - else if ((*mutex != NULL) || (ret = init_static_private(mutex)) == 0) - ret = mutex_trylock_common(mutex); - - return (ret); -} - static int mutex_lock_common(pthread_mutex_t * mutex) { @@ -1440,50 +1401,6 @@ mutex_rescan_owned(pthread_t pthread, pthread_mutex_t mutex) } } -void -_mutex_unlock_private(pthread_t pthread) -{ - struct pthread_mutex volatile *m, *m_next; - - for (m = TAILQ_FIRST(&pthread->mutexq); m != NULL; m = m_next) { - m_next = TAILQ_NEXT(m, m_qe); - if ((m->m_flags & MUTEX_FLAGS_PRIVATE) != 0) - pthread_mutex_unlock(&m); - } -} - -void -_mutex_lock_backout(pthread_t pthread) -{ - struct pthread_mutex volatile *mutex; - - /* - * Defer signals to protect the scheduling queues from - * access by the signal handler: - */ - _thread_kern_sig_defer(); - if ((pthread->flags & PTHREAD_FLAGS_IN_MUTEXQ) != 0) { - mutex = pthread->data.mutex; - - /* Lock the mutex structure: */ - _SPINLOCK(&mutex->lock); - - mutex_queue_remove(mutex, pthread); - - /* This thread is no longer waiting for the mutex: */ - pthread->data.mutex = NULL; - - /* Unlock the mutex structure: */ - _SPINUNLOCK(&mutex->lock); - - } - /* - * Undefer and handle pending signals, yielding if - * necessary: - */ - _thread_kern_sig_undefer(); -} - /* * Dequeue a waiting thread from the head of a mutex queue in descending * priority order. diff --git a/lib/libpthread/uthread/uthread_sig.c b/lib/libpthread/uthread/uthread_sig.c index d833465bf3a..a457af87b50 100644 --- a/lib/libpthread/uthread/uthread_sig.c +++ b/lib/libpthread/uthread/uthread_sig.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_sig.c,v 1.18 2003/01/27 22:22:30 marc Exp $ */ +/* $OpenBSD: uthread_sig.c,v 1.19 2003/01/31 04:46:17 marc Exp $ */ /* * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> * All rights reserved. @@ -50,6 +50,7 @@ _thread_sig_init(void) /* Clear local state */ for (i = 1; i < NSIG; i++) { + _SPINLOCK_INIT(&_thread_sigq[i - 1].lock); _thread_sigq[i - 1].pending = 0; } } @@ -104,12 +105,14 @@ _thread_sig_handler(int sig, siginfo_t *info, struct sigcontext * scp) * one. Per a POSIX suggestion, only the info for the first * of multiple activations of the same signal is kept. */ + _SPINLOCK(&_thread_sigq[sig - 1].lock); if (_thread_sigq[sig - 1].pending == 0) { sigaddset(&_process_sigpending, sig); _thread_sigq[sig - 1].pending++; memcpy(&_thread_sigq[sig - 1].siginfo, info, sizeof *info); } + _SPINUNLOCK(&_thread_sigq[sig - 1].lock); if ((_queue_signals != 0) || ((_thread_kern_in_sched == 0) && @@ -144,8 +147,8 @@ _thread_clear_pending(int sig, pthread_t thread) { pthread_t pthread; + _thread_sigq[sig - 1].pending = 0; if (sigismember(&_process_sigpending, sig)) { - _thread_sigq[sig - 1].pending = 0; sigdelset(&_process_sigpending, sig); TAILQ_FOREACH(pthread, &_thread_list, tle) { sigdelset(&pthread->sigpend, sig); @@ -363,8 +366,6 @@ _dispatch_signal(int sig, struct sigcontext * scp) struct sigaction act; void (*action)(int, siginfo_t *, void *); - _thread_clear_pending(sig, curthread); - /* save off the action and set the signal mask */ action = _thread_sigact[sig - 1].sa_sigaction; set = _thread_sigact[sig - 1].sa_mask; @@ -381,7 +382,11 @@ _dispatch_signal(int sig, struct sigcontext * scp) sigaction(sig, &act, NULL); } - /* call the action and reset the signal mask */ + /* + * clear the pending flag, deliver the signal, then reset the + * signal mask + */ + _thread_clear_pending(sig, curthread); (*action)(sig, &_thread_sigq[sig - 1].siginfo, scp); curthread->sigmask = oset; } diff --git a/lib/libpthread/uthread/uthread_sigaction.c b/lib/libpthread/uthread/uthread_sigaction.c index 61463f7ef99..a7dff2a98cb 100644 --- a/lib/libpthread/uthread/uthread_sigaction.c +++ b/lib/libpthread/uthread/uthread_sigaction.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_sigaction.c,v 1.6 2002/10/30 19:11:56 marc Exp $ */ +/* $OpenBSD: uthread_sigaction.c,v 1.7 2003/01/31 04:46:17 marc Exp $ */ /* * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> * All rights reserved. @@ -90,7 +90,7 @@ sigaction(int sig, const struct sigaction * act, struct sigaction * oact) else /* Specify the thread kernel signal handler */ gact.sa_handler = - (void (*) ()) _thread_sig_handler; + (void (*) (int)) _thread_sig_handler; /* Change the signal action in the kernel: */ if (_thread_sys_sigaction(sig, &gact, NULL) != 0) diff --git a/lib/libpthread/uthread/uthread_sigwait.c b/lib/libpthread/uthread/uthread_sigwait.c index 6e4bc5fc8a9..3b11c001352 100644 --- a/lib/libpthread/uthread/uthread_sigwait.c +++ b/lib/libpthread/uthread/uthread_sigwait.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_sigwait.c,v 1.12 2003/01/27 22:22:30 marc Exp $ */ +/* $OpenBSD: uthread_sigwait.c,v 1.13 2003/01/31 04:46:17 marc Exp $ */ /* * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>. * All rights reserved. @@ -52,7 +52,7 @@ sigwait(const sigset_t * set, int *sig) /* * Specify the thread kernel signal handler. */ - act.sa_handler = (void (*) ()) _thread_sig_handler; + act.sa_handler = (void (*) (int)) _thread_sig_handler; act.sa_flags = SA_SIGINFO | SA_RESTART; /* Ensure the signal handler cannot be interrupted by other signals: */ diff --git a/lib/libpthread/uthread/uthread_spinlock.c b/lib/libpthread/uthread/uthread_spinlock.c index 2c75863f0db..12742f5708a 100644 --- a/lib/libpthread/uthread/uthread_spinlock.c +++ b/lib/libpthread/uthread/uthread_spinlock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_spinlock.c,v 1.12 2002/09/12 23:21:42 marc Exp $ */ +/* $OpenBSD: uthread_spinlock.c,v 1.13 2003/01/31 04:46:17 marc Exp $ */ /* * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>. * All rights reserved. @@ -78,7 +78,7 @@ _spinlock(spinlock_t *lck) * returning. */ void -_spinlock_debug(spinlock_t *lck, char *fname, int lineno) +_spinlock_debug(spinlock_t *lck, const char *fname, int lineno) { struct pthread *curthread = _get_curthread(); int cnt = 0; diff --git a/lib/libpthread/uthread/uthread_write.c b/lib/libpthread/uthread/uthread_write.c index 09cd9001055..dc45cc483d7 100644 --- a/lib/libpthread/uthread/uthread_write.c +++ b/lib/libpthread/uthread/uthread_write.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_write.c,v 1.8 2001/08/21 19:24:53 fgsch Exp $ */ +/* $OpenBSD: uthread_write.c,v 1.9 2003/01/31 04:46:17 marc Exp $ */ /* * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> * All rights reserved. @@ -48,8 +48,8 @@ write(int fd, const void *buf, size_t nbytes) struct pthread *curthread = _get_curthread(); int blocking; int type; + size_t num = 0; ssize_t n; - ssize_t num = 0; ssize_t ret; /* This is a cancellation point: */ diff --git a/lib/libpthread/uthread/uthread_writev.c b/lib/libpthread/uthread/uthread_writev.c index eb5d6418a98..60b71dda10a 100644 --- a/lib/libpthread/uthread/uthread_writev.c +++ b/lib/libpthread/uthread/uthread_writev.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_writev.c,v 1.5 2001/08/21 19:24:53 fgsch Exp $ */ +/* $OpenBSD: uthread_writev.c,v 1.6 2003/01/31 04:46:17 marc Exp $ */ /* * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> * All rights reserved. @@ -51,15 +51,15 @@ writev(int fd, const struct iovec * iov, int iovcnt) int blocking; int idx = 0; int type; - ssize_t cnt; + size_t num = 0; + size_t cnt; ssize_t n; - ssize_t num = 0; ssize_t ret; struct iovec liov[20]; struct iovec *p_iov = liov; /* Check if the array size exceeds to compiled in size: */ - if (iovcnt > (sizeof(liov) / sizeof(struct iovec))) { + if (iovcnt > (int) (sizeof(liov) / sizeof(struct iovec))) { /* Allocate memory for the local array: */ if ((p_iov = (struct iovec *) malloc(iovcnt * sizeof(struct iovec))) == NULL) { @@ -134,7 +134,7 @@ writev(int fd, const struct iovec * iov, int iovcnt) * for the next write: */ p_iov[idx].iov_len -= cnt; - p_iov[idx].iov_base += cnt; + (char *)p_iov[idx].iov_base += cnt; cnt = 0; } } |