From: phk Date: Wed, 3 Dec 2008 16:40:45 +0000 (+0000) Subject: Resolve the remove/lookup race the simple way. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7d367da92ed10fbc8f9ede14b08e452adb8060c1;p=varnish Resolve the remove/lookup race the simple way. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3456 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/hash_critbit.c b/varnish-cache/bin/varnishd/hash_critbit.c index f7986492..a328dc26 100644 --- a/varnish-cache/bin/varnishd/hash_critbit.c +++ b/varnish-cache/bin/varnishd/hash_critbit.c @@ -364,6 +364,7 @@ static struct objhead * 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 @@ hcb_lookup(const struct sess *sp, struct objhead *noh) /* 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); } /*