diff options
author | deischen <deischen@FreeBSD.org> | 2004-12-18 18:07:37 +0000 |
---|---|---|
committer | deischen <deischen@FreeBSD.org> | 2004-12-18 18:07:37 +0000 |
commit | a5b13ff571d8e5b6e117756821e8aa5beb7b5d2c (patch) | |
tree | 3341fdd3fcdb8d611509d7622be5b25f271de80a /lib/libpthread/thread/thr_spinlock.c | |
parent | b231943e0e593788032a55590d7960ae015bddd2 (diff) | |
download | FreeBSD-src-a5b13ff571d8e5b6e117756821e8aa5beb7b5d2c.zip FreeBSD-src-a5b13ff571d8e5b6e117756821e8aa5beb7b5d2c.tar.gz |
Use a generic way to back threads out of wait queues when handling
signals instead of having more intricate knowledge of thread state
within signal handling.
Simplify signal code because of above (by David Xu).
Use macros for libpthread usage of pthread_cleanup_push() and
pthread_cleanup_pop(). This removes some instances of malloc()
and free() from the semaphore and pthread_once() implementations.
When single threaded and forking(), make sure that the current
thread's signal mask is inherited by the forked thread.
Use private mutexes for libc and libpthread. Signals are
deferred while threads hold private mutexes. This fix also
breaks www/linuxpluginwrapper; a patch that fixes it is at
http://people.freebsd.org/~deischen/kse/linuxpluginwrapper.diff
Fix race condition in condition variables where handling a
signal (pthread_kill() or kill()) may not see a wakeup
(pthread_cond_signal() or pthread_cond_broadcast()).
In collaboration with: davidxu
Diffstat (limited to 'lib/libpthread/thread/thr_spinlock.c')
-rw-r--r-- | lib/libpthread/thread/thr_spinlock.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/lib/libpthread/thread/thr_spinlock.c b/lib/libpthread/thread/thr_spinlock.c index deaeb9b..2b2b251 100644 --- a/lib/libpthread/thread/thr_spinlock.c +++ b/lib/libpthread/thread/thr_spinlock.c @@ -49,6 +49,10 @@ struct spinlock_extra { static void init_spinlock(spinlock_t *lck); +static struct pthread_mutex_attr static_mutex_attr = + PTHREAD_MUTEXATTR_STATIC_INITIALIZER; +static pthread_mutexattr_t static_mattr = &static_mutex_attr; + static pthread_mutex_t spinlock_static_lock; static struct spinlock_extra extra[MAX_SPINLOCKS]; static int spinlock_count = 0; @@ -65,7 +69,7 @@ _spinunlock(spinlock_t *lck) struct spinlock_extra *extra; extra = (struct spinlock_extra *)lck->fname; - pthread_mutex_unlock(&extra->lock); + _pthread_mutex_unlock(&extra->lock); } /* @@ -90,7 +94,7 @@ _spinlock(spinlock_t *lck) if (lck->fname == NULL) init_spinlock(lck); extra = (struct spinlock_extra *)lck->fname; - pthread_mutex_lock(&extra->lock); + _pthread_mutex_lock(&extra->lock); } /* @@ -112,13 +116,13 @@ _spinlock_debug(spinlock_t *lck, char *fname, int lineno) static void init_spinlock(spinlock_t *lck) { - pthread_mutex_lock(&spinlock_static_lock); + _pthread_mutex_lock(&spinlock_static_lock); if ((lck->fname == NULL) && (spinlock_count < MAX_SPINLOCKS)) { lck->fname = (char *)&extra[spinlock_count]; extra[spinlock_count].owner = lck; spinlock_count++; } - pthread_mutex_unlock(&spinlock_static_lock); + _pthread_mutex_unlock(&spinlock_static_lock); if (lck->fname == NULL) PANIC("Exceeded max spinlocks"); } @@ -133,10 +137,10 @@ _thr_spinlock_init(void) for (i = 0; i < spinlock_count; i++) _thr_mutex_reinit(&extra[i].lock); } else { - if (pthread_mutex_init(&spinlock_static_lock, NULL)) + if (_pthread_mutex_init(&spinlock_static_lock, &static_mattr)) PANIC("Cannot initialize spinlock_static_lock"); for (i = 0; i < MAX_SPINLOCKS; i++) { - if (pthread_mutex_init(&extra[i].lock, NULL)) + if (_pthread_mutex_init(&extra[i].lock, &static_mattr)) PANIC("Cannot initialize spinlock extra"); } initialized = 1; |