Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libpthread pthread_rwlock_timedrdlock() and pthread_rwlo...
details: https://anonhg.NetBSD.org/src/rev/583b9b6f82cd
branches: trunk
changeset: 572607:583b9b6f82cd
user: nathanw <nathanw%NetBSD.org@localhost>
date: Sun Jan 09 01:57:38 2005 +0000
description:
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:
lib/libpthread/pthread_rwlock.c | 16 ++++++++++++----
1 files changed, 12 insertions(+), 4 deletions(-)
diffs (46 lines):
diff -r 9019149bba94 -r 583b9b6f82cd lib/libpthread/pthread_rwlock.c
--- a/lib/libpthread/pthread_rwlock.c Sun Jan 09 01:47:20 2005 +0000
+++ b/lib/libpthread/pthread_rwlock.c Sun Jan 09 01:57:38 2005 +0000
@@ -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_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_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;
Home |
Main Index |
Thread Index |
Old Index