[Midnightbsd-cvs] src: lock.c: Don't assume the lock is in use when reinitializing a

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sun Mar 2 13:45:34 EST 2008


Log Message:
-----------
Don't assume the lock is in use when reinitializing a lockuser.  Only allocate a lockuser request if both watched and lockuser's requests are null.  Fixes some random lockup behavior with some applications forking

Modified Files:
--------------
    src/lib/libpthread/sys:
        lock.c (r1.1.1.1 -> r1.2)

-------------- next part --------------
Index: lock.c
===================================================================
RCS file: /home/cvs/src/lib/libpthread/sys/lock.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L lib/libpthread/sys/lock.c -L lib/libpthread/sys/lock.c -u -r1.1.1.1 -r1.2
--- lib/libpthread/sys/lock.c
+++ lib/libpthread/sys/lock.c
@@ -117,14 +117,23 @@
 {
 	if (lu == NULL)
 		return (-1);
-	/*
-	 * All lockusers keep their watch request and drop their
-	 * own (lu_myreq) request.  Their own request is either
-	 * some other lockuser's watch request or is the head of
-	 * the lock.
-	 */
-	lu->lu_myreq = lu->lu_watchreq;
-	if (lu->lu_myreq == NULL)
+
+	if (lu->lu_watchreq != NULL) {
+		/*
+		 * In this case the lock is active.  All lockusers
+		 * keep their watch request and drop their own
+		 * (lu_myreq) request.  Their own request is either
+		 * some other lockuser's watch request or is the
+		 * head of the lock.
+		 */
+		lu->lu_myreq = lu->lu_watchreq;
+		lu->lu_watchreq = NULL;
+       }
+       if (lu->lu_myreq == NULL)
+		/*
+		 * Oops, something isn't quite right.  Try to
+		 * allocate one.
+		 */
 		return (_lockuser_init(lu, priv));
 	else {
 		lu->lu_myreq->lr_locked = 1;


More information about the Midnightbsd-cvs mailing list