Commit 0342c5cc authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Fix an embarrasing typo in the WM-Aware binary heap layout.

The effect of this is that the root object in the binheap could be
wrong and thus hold the expiry thread hostage, even though other objects
were ripe for expiry. 

This would show up as inflated obj/objcore/objhdr counts, but have no
other deleritous effects.

Detected, conclusively, by:	sky


git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@5195 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent d4c9ffb6
......@@ -57,6 +57,9 @@ SVNID("$Id$")
*/
#define ROW_SHIFT 16
#undef PARANOIA
/* Private definitions -----------------------------------------------*/
#define ROOT_IDX 1
......@@ -127,8 +130,12 @@ child(const struct binheap *bh, unsigned u, unsigned *a, unsigned *b)
} else {
/* The rest is as usual, only inside the page */
*a = u + (u & bh->page_mask);
*b += 1;
*b = *a + 1;
}
#ifdef PARANOIA
assert(parent(bh, *a) == u);
assert(parent(bh, *b) == u);
#endif
}
......@@ -284,12 +291,29 @@ binheap_insert(struct binheap *bh, void *p)
(void)binheap_trickleup(bh, u);
}
#ifdef PARANOIA
static void
chk(const struct binheap *bh)
{
unsigned u, v;
for (u = 2; u < bh->next; u++) {
v = parent(bh, u);
assert(!bh->cmp(bh->priv, A(bh, u), A(bh, v)));
}
}
#endif
void *
binheap_root(const struct binheap *bh)
{
assert(bh != NULL);
assert(bh->magic == BINHEAP_MAGIC);
#ifdef PARANOIA
chk(bh);
#endif
return (A(bh, ROOT_IDX));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment