Date: Sun, 16 Jan 2005 01:11:10 GMT From: David Xu <davidxu@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 69098 for review Message-ID: <200501160111.j0G1BARi015244@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=69098 Change 69098 by davidxu@davidxu_tiger on 2005/01/16 01:11:08 Finally get rid of signal wrapper. Affected files ... .. //depot/projects/davidxu_thread/src/lib/libthread/Makefile#10 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/Makefile.inc#6 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_attr.c#3 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_autoinit.c#3 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_clean.c#3 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_concurrency.c#4 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_condattr.c#3 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_equal.c#3 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_fork.c#9 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_getprio.c#3 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_getschedparam.c#4 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_init.c#9 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_kern.c#13 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_kill.c#3 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_main_np.c#3 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_multi_np.c#3 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_mutex_prioceiling.c#3 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_mutex_protocol.c#3 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_mutexattr.c#3 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_once.c#3 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_private.h#18 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_pspinlock.c#8 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_resume_np.c#4 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_rtld.c#5 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_rwlockattr.c#3 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_self.c#4 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_sem.c#10 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_seterrno.c#4 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_setprio.c#3 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_setschedparam.c#4 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_sig.c#6 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_single_np.c#3 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_spec.c#3 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_spinlock.c#8 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_stack.c#4 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_suspend_np.c#4 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_switch_np.c#3 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_symbols.c#4 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_syscalls.c#5 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_yield.c#4 edit Differences ... ==== //depot/projects/davidxu_thread/src/lib/libthread/Makefile#10 (text+ko) ==== ==== //depot/projects/davidxu_thread/src/lib/libthread/thread/Makefile.inc#6 (text+ko) ==== @@ -35,7 +35,6 @@ thr_printf.c \ thr_pspinlock.c \ thr_resume_np.c \ - thr_rtld.c \ thr_rwlock.c \ thr_rwlockattr.c \ thr_self.c \ @@ -44,7 +43,6 @@ thr_setprio.c \ thr_setschedparam.c \ thr_sig.c \ - thr_sigmask.c \ thr_single_np.c \ thr_spec.c \ thr_spinlock.c \ ==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_attr.c#3 (text+ko) ==== @@ -1,4 +1,68 @@ /* + * Copyright (c) 2003 Craig Rodrigues <rodrigc@attbi.com>. + * 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 Craig Rodrigues. + * 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 CRAIG RODRIGUES 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 + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * 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. + * + */ + +/* + * Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>. + * Copyright (C) 2001 Jason Evans <jasone@freebsd.org>. + * Copyright (c) 2002,2003 Alexey Zelkin <phantom@FreeBSD.org> + * 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(s), this list of conditions and the following disclaimer + * unmodified other than the allowable addition of one or more + * copyright notices. + * 2. Redistributions in binary form must reproduce the above copyright + * notice(s), this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE + * LIABLE 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. + */ + +/* * Copyright (c) 1996 John Birrell <jb@cimlogic.com.au>. * All rights reserved. * ==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_autoinit.c#3 (text+ko) ==== ==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_clean.c#3 (text+ko) ==== ==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_concurrency.c#4 (text+ko) ==== ==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_condattr.c#3 (text+ko) ==== ==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_equal.c#3 (text+ko) ==== ==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_fork.c#9 (text+ko) ==== @@ -1,4 +1,33 @@ /* + * Copyright (c) 2005 David Xu <davidxu@freebsd.org> + * Copyright (c) 2003 Daniel Eischen <deischen@freebsd.org> + * 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. 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 THE AUTHOR 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 + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * 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. + * + * $FreeBSD: src/lib/libpthread/thread/thr_atfork.c,v 1.1 2003/11/05 03:42:10 davidxu Exp $ + */ + +/* * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> * All rights reserved. * @@ -38,7 +67,6 @@ #include <fcntl.h> #include <pthread.h> #include <spinlock.h> -#include <sys/signalvar.h> #include "libc_private.h" #include "thr_private.h" @@ -80,7 +108,6 @@ { static long inprogress, waiters; - sigset_t sigset, oldset; struct pthread *curthread; struct pthread_atfork *af; pid_t ret; @@ -93,12 +120,10 @@ curthread = _get_curthread(); /* - * Masks all signals until we reach a safe point. + * Block all signals until we reach a safe point. */ - SIGFILLSET(sigset); - __sys_sigprocmask(SIG_SETMASK, &sigset, &oldset); + _thr_signal_block(curthread); - /* We allow new hook to be added when executing hooks. */ THR_UMTX_LOCK(curthread, &_thr_atfork_lock); tmp = inprogress; while (tmp) { @@ -110,6 +135,8 @@ tmp = inprogress; } inprogress = 1; + + /* Unlock mutex, allow new hook to be added during executing hooks. */ THR_UMTX_UNLOCK(curthread, &_thr_atfork_lock); /* Run down atfork prepare handlers. */ @@ -135,8 +162,12 @@ /* Child process */ errsave = errno; inprogress = 0; - curthread->cancelflags &= ~THR_CANCEL_NEEDED; + /* + * Thread list will be reinitialized, and later we call + * _libpthread_init(), it will add us back to list. + */ + curthread->tlflags &= ~(TLFLAGS_IN_TDLIST | TLFLAGS_DETACHED); thr_self(&curthread->tid); @@ -149,11 +180,11 @@ _thr_spinlock_init(); _mutex_fork(curthread); - /* reinit library. */ + /* reinitalize library. */ _libpthread_init(curthread); - /* Restore signal mask. */ - __sys_sigprocmask(SIG_SETMASK, &oldset, NULL); + /* Ready to continue, unblock signals. */ + _thr_signal_unblock(curthread); /* Run down atfork child handlers. */ TAILQ_FOREACH(af, &_thr_atfork_list, qe) { @@ -167,8 +198,8 @@ if (unlock_malloc) _spinunlock(__malloc_lock); - /* Restore signal mask. */ - __sys_sigprocmask(SIG_SETMASK, &oldset, NULL); + /* Ready to continue, unblock signals. */ + _thr_signal_unblock(curthread); /* Run down atfork parent handlers. */ TAILQ_FOREACH(af, &_thr_atfork_list, qe) { ==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_getprio.c#3 (text+ko) ==== ==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_getschedparam.c#4 (text+ko) ==== ==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_init.c#9 (text+ko) ==== @@ -270,10 +270,8 @@ PANIC("Can't allocate initial thread"); init_main_thread(curthread); } - /* - * Add the thread to the thread list and to the KSEG's thread - * queue. + * Add the thread to the thread list queue. */ THR_LIST_ADD(curthread); _thread_active_threads = 1; @@ -338,9 +336,6 @@ thread->cancelflags = PTHREAD_CANCEL_ENABLE | PTHREAD_CANCEL_DEFERRED; thread->name = strdup("initial thread"); - /* Initialize the thread for signals: */ - SIGEMPTYSET(thread->sigmask); - /* Default the priority of the initial thread: */ thread->base_priority = THR_DEFAULT_PRIORITY; thread->active_priority = THR_DEFAULT_PRIORITY; @@ -350,14 +345,10 @@ TAILQ_INIT(&thread->mutexq); TAILQ_INIT(&thread->pri_mutexq); - /* Initialize hooks in the thread structure: */ - thread->specific = NULL; - thread->cleanup = NULL; - thread->flags = 0; - thread->sigbackout = NULL; - thread->state = PS_RUNNING; thread->uniqueid = 0; + + /* Others cleared to zero by thr_alloc() */ } static void @@ -366,7 +357,9 @@ size_t len; int mib[2]; - umtx_init(&_thread_signal_lock); + umtx_init(&_mutex_static_lock); + umtx_init(&_cond_static_lock); + umtx_init(&_rwlock_static_lock); umtx_init(&_keytable_lock); umtx_init(&_thr_atfork_lock); _thr_spinlock_init(); @@ -388,15 +381,14 @@ _pthread_attr_default.guardsize_attr = _thr_guard_default; TAILQ_INIT(&_thr_atfork_list); - } - #ifdef SYSTEM_SCOPE_ONLY - _thread_scope_system = 1; + _thread_scope_system = 1; #else - if (getenv("LIBPTHREAD_SYSTEM_SCOPE") != NULL) - _thread_scope_system = 1; - else if (getenv("LIBPTHREAD_PROCESS_SCOPE") != NULL) - _thread_scope_system = -1; + if (getenv("LIBPTHREAD_SYSTEM_SCOPE") != NULL) + _thread_scope_system = 1; + else if (getenv("LIBPTHREAD_PROCESS_SCOPE") != NULL) + _thread_scope_system = -1; #endif + } init_once = 1; } ==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_kern.c#13 (text+ko) ==== @@ -28,8 +28,8 @@ */ #include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - +#include <sys/types.h> +#include <sys/signalvar.h> #include <pthread.h> #include "thr_private.h" @@ -50,27 +50,41 @@ if (((threaded == 0) ^ (__isthreaded == 0)) == 0) return (0); + __isthreaded = threaded; +#if 0 if (threaded != 0) { -/* _thr_rtld_init(); */ - __isthreaded = 1; + _thr_rtld_init(); } else { - __isthreaded = 0; -/* _thr_rtld_fini(); */ + _thr_rtld_fini(); } +#endif return (0); } void -_thr_critical_enter(struct pthread *thread) +_thr_signal_block(struct pthread *curthread) { - thread->critical_count++; + sigset_t set; + + if (curthread->sigblock > 0) { + curthread->sigblock++; + return; + } + SIGFILLSET(set); + SIGDELSET(set, SIGBUS); + SIGDELSET(set, SIGILL); + SIGDELSET(set, SIGFPE); + SIGDELSET(set, SIGSEGV); + SIGDELSET(set, SIGTRAP); + __sys_sigprocmask(SIG_BLOCK, &set, &curthread->sigmask); + curthread->sigblock++; } void -_thr_critical_leave(struct pthread *thread) +_thr_signal_unblock(struct pthread *curthread) { - thread->critical_count--; - THR_CRITICAL_CHECK(thread); + if (--curthread->sigblock == 0) + __sys_sigprocmask(SIG_SETMASK, &curthread->sigmask, NULL); } void ==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_kill.c#3 (text+ko) ==== @@ -55,8 +55,7 @@ */ else if ((ret = _thr_ref_add(curthread, pthread, /*include dead*/0)) == 0) { - if ((sig > 0) && - (_thread_sigact[sig - 1].sa_handler != SIG_IGN)) + if (sig > 0) thr_kill(pthread->tid, sig); _thr_ref_delete(curthread, pthread); } ==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_main_np.c#3 (text+ko) ==== ==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_multi_np.c#3 (text+ko) ==== ==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_mutex_prioceiling.c#3 (text+ko) ==== ==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_mutex_protocol.c#3 (text+ko) ==== ==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_mutexattr.c#3 (text+ko) ==== @@ -31,6 +31,41 @@ * * $FreeBSD$ */ + +/* + * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>. + * 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 + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * 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. + * + * $FreeBSD$ + */ + #include <string.h> #include <stdlib.h> #include <errno.h> ==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_once.c#3 (text+ko) ==== ==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_private.h#18 (text+ko) ==== @@ -74,7 +74,7 @@ /* * Kernel fatal error handler macro. */ -#define PANIC(string) _thr_exit(__FILE__,__LINE__,string) +#define PANIC(string) _thread_exit(__FILE__,__LINE__,string) /* Output debug messages like this: */ #define stdout_debug(args...) _thread_printf(STDOUT_FILENO, ##args) @@ -159,14 +159,6 @@ #define PTHREAD_MUTEXATTR_STATIC_INITIALIZER \ { PTHREAD_MUTEX_DEFAULT, PTHREAD_PRIO_NONE, 0, MUTEX_FLAGS_PRIVATE } -/* - * Condition variable definitions. - */ -enum pthread_cond_type { - COND_TYPE_FAST, - COND_TYPE_MAX -}; - struct pthread_cond { /* * Lock for accesses to this structure. @@ -179,16 +171,14 @@ }; struct pthread_cond_attr { - enum pthread_cond_type c_type; - long c_flags; + long c_flags; }; struct pthread_barrier { - pthread_mutex_t b_lock; - pthread_cond_t b_cond; + struct umtx b_lock; + long b_cycle; int b_count; int b_waiters; - int b_cycle; }; struct pthread_barrierattr { @@ -324,18 +314,6 @@ pthread_mutex_t mutex; }; -/* - * Define a continuation routine that can be used to perform a - * transfer of control: - */ -typedef void (*thread_continuation_t) (void *); - -struct join_status { - struct pthread *thread; - void *ret; - int error; -}; - struct pthread_specific_elem { const void *data; int seqno; @@ -366,8 +344,8 @@ */ struct umtx lock; - /* Thread exits in kernel, written by kernel. */ - long isdead; + /* Thread is terminated in kernel, written by kernel. */ + long terminated; /* Kernel thread id. */ long tid; @@ -378,11 +356,8 @@ /* How many low level locks the thread held. */ int locklevel; - /* - * Set to non-zero when this thread has entered a critical - * region. We allow for recursive entries into critical regions. - */ - int critical_count; + /* Signal blocked counter. */ + int sigblock; /* Queue entry for list of all threads. */ TAILQ_ENTRY(pthread) tle; /* link for all threads in process */ @@ -424,16 +399,8 @@ /* Thread temporary signal mask. */ sigset_t sigmask; - /* Used for tracking delivery of signal handlers. */ - sigset_t sigpend; - siginfo_t siginfo[_SIG_MAXSIG]; - volatile int check_pending; - - /* backout routine must be invoke before handling signal. */ - thread_continuation_t sigbackout; - /* Thread state: */ - enum pthread_state state; + long state; /* * Error variable used instead of errno. The function __error() @@ -446,7 +413,6 @@ * join status keeps track of a join operation to another thread. */ struct pthread *joiner; - struct join_status join_status; /* * The current thread can belong to a priority mutex queue. @@ -547,24 +513,6 @@ #define THR_UMTX_OWNED(thrd, lck) \ (umtx_owner((struct umtx *)lck) == (thrd)->tid) -/* - * Critical regions can also be detected by looking at the threads - * current lock level. Ensure these macros increment and decrement - * the lock levels such that locks can not be held with a lock level - * of 0. - */ -#define THR_IN_CRITICAL(thrd) \ - (((thrd)->locklevel > 0) || \ - ((thrd)->critical_count > 0)) - -#define THR_CRITICAL_CHECK(thrd) \ -do { \ - if (!THR_IN_CRITICAL(thrd)) { \ - if ((thrd)->check_pending != 0) \ - _thr_sig_check_pending(thrd); \ - } \ -} while (0) - #define THR_LOCK_ACQUIRE(thrd, lck) \ do { \ (thrd)->locklevel++; \ @@ -576,7 +524,6 @@ if ((thrd)->locklevel > 0) { \ umtx_unlock((struct umtx *)(lck), (thrd)->tid); \ (thrd)->locklevel--; \ - THR_CRITICAL_CHECK(thrd); \ } else { \ _thr_assert_lock_level(); \ } \ @@ -587,8 +534,15 @@ #define THR_THREAD_LOCK(curthrd, thr) THR_LOCK_ACQUIRE(curthrd, &(thr)->lock) #define THR_THREAD_UNLOCK(curthrd, thr) THR_LOCK_RELEASE(curthrd, &(thr)->lock) -#define THREAD_LIST_LOCK(curthrd) THR_LOCK_ACQUIRE((curthrd), &_thread_list_lock) -#define THREAD_LIST_UNLOCK(curthrd) THR_LOCK_RELEASE((curthrd), &_thread_list_lock) +#define THREAD_LIST_LOCK(curthrd) \ +do { \ + THR_LOCK_ACQUIRE((curthrd), &_thr_list_lock); \ +} while (0) + +#define THREAD_LIST_UNLOCK(curthrd) \ +do { \ + THR_LOCK_RELEASE((curthrd), &_thr_list_lock); \ +} while (0) /* * Macros to insert/remove threads to the all thread list and @@ -625,13 +579,6 @@ #define GC_NEEDED() (atomic_load_acq_int(&_gc_count) >= 5) -#define THR_CRITICAL_ENTER(thr) (thr)->critical_count++ -#define THR_CRITICAL_LEAVE(thr) do { \ - (thr)->critical_count--; \ - THR_CRITICAL_CHECK(thr); \ - } \ -} while (0) - #define THR_IN_SYNCQ(thrd) (((thrd)->sflags & THR_FLAGS_IN_SYNCQ) != 0) extern int __isthreaded; @@ -673,7 +620,7 @@ /* Default condition variable attributes: */ SCLASS struct pthread_cond_attr _pthread_condattr_default - SCLASS_PRESET({COND_TYPE_FAST, 0}); + SCLASS_PRESET({PTHREAD_PROCESS_PRIVATE}); /* Array of signal actions for this process: */ SCLASS struct sigaction _thread_sigact[_SIG_MAXSIG]; @@ -684,9 +631,11 @@ /* Garbage thread count. */ SCLASS int _gc_count SCLASS_PRESET(0); +SCLASS struct umtx _mutex_static_lock; +SCLASS struct umtx _cond_static_lock; +SCLASS struct umtx _rwlock_static_lock; SCLASS struct umtx _keytable_lock; -SCLASS struct umtx _thread_list_lock; -SCLASS struct umtx _thread_signal_lock; +SCLASS struct umtx _thr_list_lock; /* Undefine the storage class and preset specifiers: */ #undef SCLASS @@ -696,8 +645,6 @@ * Function prototype definitions. */ __BEGIN_DECLS -void _thr_list_init(); -void _thr_single_thread(struct pthread *); int _thr_setthreaded(int); int _mutex_cv_lock(pthread_mutex_t *); int _mutex_cv_unlock(pthread_mutex_t *); @@ -727,7 +674,7 @@ void _pthread_cleanup_push(void (*routine) (void *), void *routine_arg); void _pthread_cleanup_pop(int execute); struct pthread *_thr_alloc(struct pthread *); -void _thr_exit(char *, int, char *) __dead2; +void _thread_exit(char *, int, char *) __dead2; void _thr_exit_cleanup(void); int _thr_ref_add(struct pthread *, struct pthread *, int); void _thr_ref_delete(struct pthread *, struct pthread *); @@ -741,16 +688,14 @@ void _thread_cleanupspecific(void); void _thread_dump_info(void); void _thread_printf(int, const char *, ...); -void _thr_sig_handler(int, siginfo_t *, ucontext_t *); -void _thr_sig_check_pending(struct pthread *); -void _thr_sig_rundown(struct pthread *); void _thr_spinlock_init(void); int _thr_cancel_enter(struct pthread *); void _thr_cancel_leave(struct pthread *, int); -void _thr_critical_enter(struct pthread *); -void _thr_critical_leave(struct pthread *); +void _thr_signal_block(struct pthread *); +void _thr_signal_unblock(struct pthread *); void _thr_signal_init(void); void _thr_signal_deinit(void); +void _thr_list_init(); void _thr_hash_add(struct pthread *); void _thr_hash_remove(struct pthread *); struct pthread *_thr_hash_find(struct pthread *); @@ -855,8 +800,6 @@ int __sys_msync(void *, size_t, int); #endif -__END_DECLS - static inline int _thr_isthreaded(void) { @@ -876,4 +819,6 @@ _libpthread_init(0); } +__END_DECLS + #endif /* !_THR_PRIVATE_H */ ==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_pspinlock.c#8 (text+ko) ==== @@ -31,7 +31,7 @@ #include <pthread.h> #include "thr_private.h" -#define SPIN_COUNT 10000 +#define SPIN_COUNT 100000 __weak_reference(_pthread_spin_init, pthread_spin_init); __weak_reference(_pthread_spin_destroy, pthread_spin_destroy); @@ -100,15 +100,18 @@ else { count = SPIN_COUNT; while ((ret = umtx_trylock(&lck->s_lock, self->tid)) != 0) { + while (*(volatile long *)&lck->s_lock.u_owner) { #ifdef __i386__ - /* tell cpu we are spinning */ - __asm __volatile("pause"); + /* tell cpu we are spinning */ + __asm __volatile("pause"); #endif - if (--count <= 0) { - count = SPIN_COUNT; - _pthread_yield(); + if (--count <= 0) { + count = SPIN_COUNT; + _pthread_yield(); + } } } + ret = 0; } return (ret); ==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_resume_np.c#4 (text+ko) ==== ==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_rtld.c#5 (text+ko) ==== ==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_rwlockattr.c#3 (text+ko) ==== ==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_self.c#4 (text+ko) ==== ==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_sem.c#10 (text+ko) ==== ==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_seterrno.c#4 (text+ko) ==== ==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_setprio.c#3 (text+ko) ==== ==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_setschedparam.c#4 (text+ko) ==== ==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_sig.c#6 (text+ko) ==== @@ -1,6 +1,5 @@ /* * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> - * Copyright (c) 2005 David Xu <davidxu@freebsd.org> * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -30,8 +29,9 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/libpthread/thread/thr_sig.c,v 1.82 2004/11/01 10:49:34 davidxu Exp $ + * $FreeBSD$ */ + #include <sys/param.h> #include <sys/types.h> #include <sys/signalvar.h> @@ -50,228 +50,195 @@ #define DBG_MSG(x...) #endif -typedef void (*ohandler)(int sig, int code, - struct sigcontext *scp, char *addr, __sighandler_t *catcher); -static void thr_cancel_handler(struct pthread *); - -void -_thr_sig_handler(int sig, siginfo_t *info, ucontext_t *ucp) +static void +sigcancel_handler(int sig, siginfo_t *info, ucontext_t *ucp) { - __siginfohandler_t *sigfunc; - struct pthread *curthread; - struct sigaction act; - int sa_flags, err_save; - - err_save = errno; - - DBG_MSG(">>> _thr_sig_handler(%d)\n", sig); - - curthread = _get_curthread(); - if (curthread == NULL) - PANIC("No current thread.\n"); - if (curthread->state == PS_DEAD) { - errno = err_save; - return; - } - - /* - * If thread is in critical region or if thread is on - * the way of state transition, then latch signal into buffer. - */ - if (THR_IN_CRITICAL(curthread)) { - DBG_MSG(">>> _thr_sig_handler(%d) in critical\n", sig); - curthread->siginfo[sig-1] = *info; - curthread->check_pending = 1; - SIGADDSET(curthread->sigpend, sig); - errno = err_save; - return; - } - - /* Check the threads previous state: */ - curthread->critical_count++; - if (curthread->sigbackout != NULL) - curthread->sigbackout((void *)curthread); - curthread->critical_count--; - - if (sig == SIGCANCEL) - thr_cancel_handler(curthread); - - THR_ASSERT(!(curthread->sigbackout), "sigbackout was not cleared."); - - /* Reset signal handler if needed */ - THR_LOCK_ACQUIRE(curthread, &_thread_signal_lock); - sigfunc = _thread_sigact[sig - 1].sa_sigaction; - sa_flags = _thread_sigact[sig - 1].sa_flags; - if (sa_flags & SA_RESETHAND) { - act.sa_handler = SIG_DFL; - act.sa_flags = SA_RESTART; - SIGEMPTYSET(act.sa_mask); - __sys_sigaction(sig, &act, NULL); - __sys_sigaction(sig, NULL, &_thread_sigact[sig - 1]); - } - THR_LOCK_RELEASE(curthread, &_thread_signal_lock); - - /* Now invoke real handler */ - if (((__sighandler_t *)sigfunc != SIG_DFL) && - ((__sighandler_t *)sigfunc != SIG_IGN) && - (sigfunc != (__siginfohandler_t *)_thr_sig_handler)) { - if ((sa_flags & SA_SIGINFO) != 0 || info == NULL) - (*(sigfunc))(sig, info, ucp); - else { - ((ohandler)(*sigfunc))( - sig, info->si_code, (struct sigcontext *)ucp, - info->si_addr, (__sighandler_t *)sigfunc); - } - } else if (sig != SIGCANCEL && (__sighandler_t *)sigfunc == SIG_DFL) { - thr_kill(curthread->tid, sig); - } - - SIGDELSET(ucp->uc_sigmask, SIGCANCEL); + struct pthread *curthread = _get_curthread(); - DBG_MSG("<<< _thr_sig_handler(%d)\n", sig); - - errno = err_save; -} - -/* - * This is called by a thread when it has pending signals to deliver. - * It should only be called from the context of the thread. - */ -void -_thr_sig_rundown(struct pthread *curthread) -{ - int i, err_save; - sigset_t sigmask, oldmask; - - err_save = errno; - - DBG_MSG(">>> thr_sig_rundown (%p)\n", curthread); - - SIGFILLSET(sigmask); - /* repost signal to kernel */ - if (!SIGISEMPTY(curthread->sigpend)) { - __sys_sigprocmask(SIG_SETMASK, &sigmask, &oldmask); - for (i = 1; i <= _SIG_MAXSIG; ++i) { - if (SIGISMEMBER(curthread->sigpend, i)) { - SIGDELSET(curthread->sigpend, i); - if (!_thr_isthreaded()) - kill(getpid(), i); - else - thr_kill(curthread->tid, i); - } - } - __sys_sigprocmask(SIG_SETMASK, &oldmask, NULL); - } - DBG_MSG("<<< thr_sig_rundown (%p)\n", curthread); - errno = err_save; -} - -/* - * This checks pending signals for the current thread. - */ -void -_thr_sig_check_pending(struct pthread *curthread) -{ - int errsave; - - if (THR_IN_CRITICAL(curthread)) - return; - - errsave = errno; - curthread->check_pending = 0; - _thr_sig_rundown(curthread); - errno = errsave; -} - -static void -thr_cancel_handler(struct pthread *curthread) -{ if (curthread->cancelflags & THR_CANCEL_AT_POINT) pthread_testcancel(); - _thr_suspend_check(curthread); + if (curthread->flags & THR_FLAGS_NEED_SUSPEND) { + __sys_sigprocmask(SIG_SETMASK, &ucp->uc_sigmask, NULL); + _thr_suspend_check(curthread); + } } - void _thr_suspend_check(struct pthread *curthread) { - sigset_t set; long cycle; /* Async suspend. */ + _thr_signal_block(curthread); THR_LOCK(curthread); if ((curthread->flags & (THR_FLAGS_NEED_SUSPEND | THR_FLAGS_SUSPENDED)) == THR_FLAGS_NEED_SUSPEND) { curthread->flags |= THR_FLAGS_SUSPENDED; - SIGEMPTYSET(set); - SIGADDSET(set, SIGCANCEL); >>> TRUNCATED FOR MAIL (1000 lines) <<<
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200501160111.j0G1BARi015244>