diff options
| author | ad <ad@NetBSD.org> | 2007-08-04 13:37:48 +0000 |
|---|---|---|
| committer | ad <ad@NetBSD.org> | 2007-08-04 13:37:48 +0000 |
| commit | 50fa8db4e44b07accbfd5f2821987476be3bf05c (patch) | |
| tree | 04cfc58059fb658923f9a7b24583dd0b3e4437d1 /lib/libpthread/sem.c | |
| parent | b108f67c054e0f87f9b653c4d194652a4bfc40cc (diff) | |
Some significant performance improvements, and a fix for a race with pthread
detach/join.
- Make mutex acquire spin for a short time, as done with spinlocks.
- Make the number of spins controllable with the env var PTHREAD_NSPINS.
- Reduce the amount of time that libpthread internal spinlocks are held.
- Rely more on the barrier effects of park/unpark to avoid taking spinlocks.
- Simplify the locking around pthreads and the global queues.
- Align per-thread sync data on a 128 byte boundary.
- Offset thread stacks by a small amount to try and reduce cache thrash.
Diffstat (limited to 'lib/libpthread/sem.c')
| -rw-r--r-- | lib/libpthread/sem.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/libpthread/sem.c b/lib/libpthread/sem.c index 44fe2940102..b659cf33719 100644 --- a/lib/libpthread/sem.c +++ b/lib/libpthread/sem.c @@ -1,4 +1,4 @@ -/* $NetBSD: sem.c,v 1.14 2007/03/24 18:52:00 ad Exp $ */ +/* $NetBSD: sem.c,v 1.15 2007/08/04 13:37:50 ad Exp $ */ /*- * Copyright (c) 2003, 2006, 2007 The NetBSD Foundation, Inc. @@ -66,7 +66,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: sem.c,v 1.14 2007/03/24 18:52:00 ad Exp $"); +__RCSID("$NetBSD: sem.c,v 1.15 2007/08/04 13:37:50 ad Exp $"); #include <sys/types.h> #include <sys/ksem.h> @@ -92,7 +92,7 @@ struct _sem_st { /* Protects data below. */ pthread_spin_t usem_interlock; - struct pthread_queue_t usem_waiters; + pthread_queue_t usem_waiters; unsigned int usem_count; }; @@ -287,7 +287,7 @@ sem_wait(sem_t *sem) { pthread_t self; extern int pthread__started; - struct pthread_queue_t *queue; + pthread_queue_t *queue; #ifdef ERRORCHECK if (sem == NULL || *sem == NULL || (*sem)->usem_magic != USEM_MAGIC) { @@ -333,8 +333,10 @@ sem_wait(sem_t *sem) PTQ_INSERT_TAIL(queue, self, pt_sleep); self->pt_sleeponq = 1; self->pt_sleepobj = queue, + pthread_spinunlock(self, &(*sem)->usem_interlock); (void)pthread__park(self, &(*sem)->usem_interlock, queue, NULL, 1, queue); + pthread_spinlock(self, &(*sem)->usem_interlock); } (*sem)->usem_count--; pthread_spinunlock(self, &(*sem)->usem_interlock); |
