r3384 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Tue Nov 11 14:38:09 CET 2008


Author: phk
Date: 2008-11-11 14:38:09 +0100 (Tue, 11 Nov 2008)
New Revision: 3384

Modified:
   trunk/varnish-cache/bin/varnishd/cache_lck.c
Log:
Have I mentioned that I think POSIX is a bunch of amateurs ?

There is no NULL value for pthread_t and you have to call a function
to compare them.



Modified: trunk/varnish-cache/bin/varnishd/cache_lck.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_lck.c	2008-11-11 13:15:01 UTC (rev 3383)
+++ trunk/varnish-cache/bin/varnishd/cache_lck.c	2008-11-11 13:38:09 UTC (rev 3384)
@@ -52,6 +52,7 @@
 	unsigned		magic;
 #define ILCK_MAGIC		0x7b86c8a5
 	pthread_mutex_t		mtx;
+	int			held;
 	pthread_t		owner;
 	VTAILQ_ENTRY(ilck)	list;
 	const char		*w;
@@ -71,8 +72,9 @@
 	CAST_OBJ_NOTNULL(ilck, lck->priv, ILCK_MAGIC);
 	if (!(params->diag_bitmap & 0x18)) {
 		AZ(pthread_mutex_lock(&ilck->mtx));
-		AZ(ilck->owner);
+		AZ(ilck->held);
 		ilck->owner = pthread_self();
+		ilck->held = 1;
 		return;
 	}
 	r = pthread_mutex_trylock(&ilck->mtx);
@@ -83,8 +85,9 @@
 	} else if (params->diag_bitmap & 0x8) {
 		VSL(SLT_Debug, 0, "MTX_LOCK(%s,%s,%d,%s)", p, f, l, ilck->w);
 	}
-	AZ(ilck->owner);
+	AZ(ilck->held);
 	ilck->owner = pthread_self();
+	ilck->held = 1;
 }
 
 void
@@ -93,8 +96,9 @@
 	struct ilck *ilck;
 
 	CAST_OBJ_NOTNULL(ilck, lck->priv, ILCK_MAGIC);
-	assert(ilck->owner == pthread_self());
-	ilck->owner = NULL;
+	assert(pthread_equal(ilck->owner, pthread_self()));
+	AN(ilck->held);
+	ilck->held = 0;
 	AZ(pthread_mutex_unlock(&ilck->mtx));
 	if (params->diag_bitmap & 0x8)
 		VSL(SLT_Debug, 0, "MTX_UNLOCK(%s,%s,%d,%s)", p, f, l, ilck->w);
@@ -113,7 +117,8 @@
 		VSL(SLT_Debug, 0,
 		    "MTX_TRYLOCK(%s,%s,%d,%s) = %d", p, f, l, ilck->w);
 	if (r == 0) {
-		AZ(ilck->owner);
+		AZ(ilck->held);
+		ilck->held = 1;
 		ilck->owner = pthread_self();
 	}
 	return (r);
@@ -126,9 +131,11 @@
 
 	CAST_OBJ_NOTNULL(ilck, lck->priv, ILCK_MAGIC);
 	if (held)
-		assert(ilck->owner == pthread_self());
+		assert(ilck->held &&
+		    pthread_equal(ilck->owner, pthread_self()));
 	else
-		assert(ilck->owner != pthread_self());
+		assert(!ilck->held ||
+		    !pthread_equal(ilck->owner, pthread_self()));
 }
 
 void
@@ -137,10 +144,11 @@
 	struct ilck *ilck;
 
 	CAST_OBJ_NOTNULL(ilck, lck->priv, ILCK_MAGIC);
-	assert(ilck->owner == pthread_self());
-	ilck->owner = NULL;
+	AN(ilck->held);
+	assert(pthread_equal(ilck->owner, pthread_self()));
+	ilck->held = 0;
 	AZ(pthread_cond_wait(cond, &ilck->mtx));
-	AZ(ilck->owner);
+	AZ(ilck->held);
 	ilck->owner = pthread_self();
 }
 




More information about the varnish-commit mailing list