diff options
| author | ad <ad@NetBSD.org> | 2007-09-13 23:51:47 +0000 |
|---|---|---|
| committer | ad <ad@NetBSD.org> | 2007-09-13 23:51:47 +0000 |
| commit | 20e3392edc8d116aa42fc6fb3daa1456c090dd49 (patch) | |
| tree | a83f6a4f3f9a0f3a1f2e158f023ee09c9404c1b6 /lib/libpthread/pthread_cond.c | |
| parent | aff14ee9c85d5f7ef3c66280a8dbf7056dd34b67 (diff) | |
Add a per-mutex deferred wakeup flag so that threads doing something like
the following do not wake other threads early:
pthread_mutex_lock(&mutex);
pthread_cond_broadcast(&cond);
foo = malloc(100); /* takes libc mutexes */
pthread_mutex_unlock(&mutex);
Diffstat (limited to 'lib/libpthread/pthread_cond.c')
| -rw-r--r-- | lib/libpthread/pthread_cond.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/libpthread/pthread_cond.c b/lib/libpthread/pthread_cond.c index 2f8879c1dee..4266250ed72 100644 --- a/lib/libpthread/pthread_cond.c +++ b/lib/libpthread/pthread_cond.c @@ -1,4 +1,4 @@ -/* $NetBSD: pthread_cond.c,v 1.36 2007/09/08 22:49:50 ad Exp $ */ +/* $NetBSD: pthread_cond.c,v 1.37 2007/09/13 23:51:47 ad Exp $ */ /*- * Copyright (c) 2001, 2006, 2007 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: pthread_cond.c,v 1.36 2007/09/08 22:49:50 ad Exp $"); +__RCSID("$NetBSD: pthread_cond.c,v 1.37 2007/09/13 23:51:47 ad Exp $"); #include <errno.h> #include <sys/time.h> @@ -324,8 +324,8 @@ pthread_cond_signal(pthread_cond_t *cond) * deferred wakeup list. The waiter will be set running when the * caller (this thread) releases the mutex. */ - if (mutex != NULL && pthread__mutex_owned(self, mutex) && - self->pt_nwaiters < pthread__unpark_max) { + if (mutex != NULL && self->pt_nwaiters < pthread__unpark_max && + pthread__mutex_deferwake(self, mutex)) { signaled->pt_sleepobj = NULL; signaled->pt_sleeponq = 0; pthread_spinunlock(&cond->ptc_lock); @@ -363,7 +363,7 @@ pthread_cond_broadcast(pthread_cond_t *cond) * Try to defer waking threads (see pthread_cond_signal()). * Only transfer waiters for which there is no pending wakeup. */ - if (mutex != NULL && pthread__mutex_owned(self, mutex)) { + if (mutex != NULL && pthread__mutex_deferwake(self, mutex)) { for (signaled = PTQ_FIRST(&cond->ptc_waiters); signaled != NULL; signaled = next) { |
