summaryrefslogtreecommitdiff
path: root/lib/libpthread
diff options
context:
space:
mode:
authornathanw <nathanw@NetBSD.org>2005-01-09 01:57:38 +0000
committernathanw <nathanw@NetBSD.org>2005-01-09 01:57:38 +0000
commitefffd0e96a56a077ccc2c3d66a82071c2445341e (patch)
tree3184da93e3c3cb5a8b35563e0b17c98e73f753c9 /lib/libpthread
parent6a562a3a84df04c9c73ef7c6bac4f2df98f95b25 (diff)
pthread_rwlock_timedrdlock() and pthread_rwlock_timedwrlock():
After exiting the try-again loop, make one more test of the lock conditions, in case it was released while a signal handler kept the thread busy past the alarm expiration.
Diffstat (limited to 'lib/libpthread')
-rw-r--r--lib/libpthread/pthread_rwlock.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/libpthread/pthread_rwlock.c b/lib/libpthread/pthread_rwlock.c
index 3da4632739d..a15a3d4bf84 100644
--- a/lib/libpthread/pthread_rwlock.c
+++ b/lib/libpthread/pthread_rwlock.c
@@ -1,4 +1,4 @@
-/* $NetBSD: pthread_rwlock.c,v 1.10 2005/01/09 01:47:20 nathanw Exp $ */
+/* $NetBSD: pthread_rwlock.c,v 1.11 2005/01/09 01:57:38 nathanw Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: pthread_rwlock.c,v 1.10 2005/01/09 01:47:20 nathanw Exp $");
+__RCSID("$NetBSD: pthread_rwlock.c,v 1.11 2005/01/09 01:57:38 nathanw Exp $");
#include <errno.h>
@@ -296,8 +296,14 @@ pthread_rwlock_timedrdlock(pthread_rwlock_t *rwlock,
pthread_spinlock(self, &rwlock->ptr_interlock);
}
- if (retval == 0)
+ /* One last chance to get the lock, in case it was released between
+ the alarm firing and when this thread got rescheduled, or in case
+ a signal handler kept it busy */
+ if ((rwlock->ptr_writer == NULL) &&
+ (PTQ_EMPTY(&rwlock->ptr_wblocked))) {
rwlock->ptr_nreaders++;
+ retval = 0;
+ }
pthread_spinunlock(self, &rwlock->ptr_interlock);
return retval;
@@ -359,8 +365,10 @@ pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock,
pthread_spinlock(self, &rwlock->ptr_interlock);
}
- if (retval == 0)
+ if ((rwlock->ptr_nreaders == 0) && (rwlock->ptr_writer == NULL)) {
rwlock->ptr_writer = self;
+ retval = 0;
+ }
pthread_spinunlock(self, &rwlock->ptr_interlock);
return retval;