r3456 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Wed Dec 3 17:40:46 CET 2008


Author: phk
Date: 2008-12-03 17:40:45 +0100 (Wed, 03 Dec 2008)
New Revision: 3456

Modified:
   trunk/varnish-cache/bin/varnishd/hash_critbit.c
Log:
Resolve the remove/lookup race the simple way.



Modified: trunk/varnish-cache/bin/varnishd/hash_critbit.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/hash_critbit.c	2008-12-03 10:50:04 UTC (rev 3455)
+++ trunk/varnish-cache/bin/varnishd/hash_critbit.c	2008-12-03 16:40:45 UTC (rev 3456)
@@ -364,6 +364,7 @@
 hcb_lookup(const struct sess *sp, struct objhead *noh)
 {
 	struct objhead *oh;
+	unsigned u;
 	
 	assert(params->hash_sha256);
 	oh =  hcb_insert(&hcb_root, noh, 0);
@@ -371,14 +372,14 @@
 		/* Assert that we didn't muck with the tree without lock */
 		assert(oh != noh);
 		Lck_Lock(&oh->mtx);
-		oh->refcnt++;
+		u = oh->refcnt;
+		if (u)
+			oh->refcnt++;
 		Lck_Unlock(&oh->mtx);
-		VSL_stats->hcb_nolock++;
-		if (0) {
-			fprintf(stderr, "%s %d\n", __func__, __LINE__);
-			dump(&hcb_root, stderr);
+		if (u) {
+			VSL_stats->hcb_nolock++;
+			return (oh);
 		}
-		return (oh);
 	}
 
 	/*



More information about the varnish-commit mailing list