From 1670c84769cee64e56b3e48fe41e4fa433d81b81 Mon Sep 17 00:00:00 2001 From: phk Date: Tue, 18 Jul 2006 13:19:55 +0000 Subject: [PATCH] Delete binheap root by it's index. Expect a refcount of one (the one holding the object in the hash) git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@494 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache_expire.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache_expire.c b/varnish-cache/bin/varnishd/cache_expire.c index b4428099..2ca0ad82 100644 --- a/varnish-cache/bin/varnishd/cache_expire.c +++ b/varnish-cache/bin/varnishd/cache_expire.c @@ -24,6 +24,7 @@ void EXP_Insert(struct object *o) { + assert(o->heap_idx == 0); AZ(pthread_mutex_lock(&exp_mtx)); binheap_insert(exp_heap, o); AZ(pthread_mutex_unlock(&exp_mtx)); @@ -32,6 +33,7 @@ EXP_Insert(struct object *o) void EXP_TTLchange(struct object *o) { + assert(o->heap_idx != 0); AZ(pthread_mutex_lock(&exp_mtx)); binheap_delete(exp_heap, o->heap_idx); binheap_insert(exp_heap, o); @@ -54,17 +56,19 @@ exp_hangman(void *arg) t = time(NULL); AZ(pthread_mutex_lock(&exp_mtx)); TAILQ_FOREACH(o, &exp_deathrow, deathrow) { - if (o->ttl >= t) + if (o->ttl >= t) { + o = NULL; break; + } if (o->busy) { VSL(SLT_Debug, 0, "Grim Reaper: Busy object xid %u", o->xid); continue; } - if (o->refcnt == 0) + if (o->refcnt == 1) break; } - if (o == NULL || o->ttl >= t || o->refcnt > 0) { + if (o == NULL) { AZ(pthread_mutex_unlock(&exp_mtx)); AZ(sleep(1)); continue; @@ -103,7 +107,7 @@ exp_prefetch(void *arg) AZ(sleep(1)); continue; } - binheap_delete(exp_heap, 0); + binheap_delete(exp_heap, o->heap_idx); AZ(pthread_mutex_unlock(&exp_mtx)); VSL(SLT_ExpPick, 0, "%u", o->xid); -- 2.39.5