This is the mail archive of the libc-alpha@sourceware.cygnus.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Another LinuxThreads read-write lock patch.


This one fixes two things. In adding the new rwlock attribute, I omitted 
to add it to the sanity check in the attribute setting function.

Also, I found a bug in the write-lock case of pthread_rwlock_unlock.  If
preference is given to readers, the logic ignores a waiting writer, even if no
waiting readers are actualy present!  The correct algorithm is to only give
preference to readers if they are actually there, otherwise turn
the attention back to any waiting writers.

I have now tested locks with all three attributes; though in practice only the
default one really counts, since the other are all non-portable.

I have the warm fuzzies about this now.  Ship, or get off the pot!

(Yes, Andreas, I will get that test code to you, just hang on!)

Index: linuxthreads/rwlock.c
diff -u linuxthreads/rwlock.c:1.1.1.2 linuxthreads/rwlock.c:1.1.1.2.2.1
--- linuxthreads/rwlock.c:1.1.1.2	Wed Jan 12 19:06:52 2000
+++ linuxthreads/rwlock.c	Wed Jan 12 19:48:18 2000
@@ -362,8 +362,9 @@
 	}
       rwlock->__rw_writer = NULL;
 
-      if (rwlock->__rw_kind == PTHREAD_RWLOCK_PREFER_READER_NP
-	  || (th = dequeue (&rwlock->__rw_write_waiting)) == NULL)
+      if ((rwlock->__rw_kind == PTHREAD_RWLOCK_PREFER_READER_NP
+	  && !queue_is_empty(&rwlock->__rw_read_waiting))
+	  || (th = dequeue(&rwlock->__rw_write_waiting)) == NULL)
 	{
 	  /* Restart all waiting readers.  */
 	  torestart = rwlock->__rw_read_waiting;
@@ -477,6 +478,7 @@
 {
   if (pref != PTHREAD_RWLOCK_PREFER_READER_NP
       && pref != PTHREAD_RWLOCK_PREFER_WRITER_NP
+      && pref != PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP
       && pref != PTHREAD_RWLOCK_DEFAULT_NP)
     return EINVAL;
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]