Mailing List Archive

[master] a016850fb rename binheap / binary_heap -> vbh
commit a016850fbb8fe32c1f2f326045646126ea4154af
Author: Nils Goroll <nils.goroll@uplex.de>
Date: Tue Aug 4 07:09:55 2020 +0200

rename binheap / binary_heap -> vbh

with the public api functions called VBH_

diff --git a/bin/varnishd/cache/cache_backend_probe.c b/bin/varnishd/cache/cache_backend_probe.c
index 4db99c2c1..51fd00754 100644
--- a/bin/varnishd/cache/cache_backend_probe.c
+++ b/bin/varnishd/cache/cache_backend_probe.c
@@ -46,7 +46,7 @@

#include "cache_varnishd.h"

-#include "binary_heap.h"
+#include "vbh.h"
#include "vcli_serve.h"
#include "vsa.h"
#include "vtcp.h"
@@ -89,7 +89,7 @@ struct vbp_target {

static struct lock vbp_mtx;
static pthread_cond_t vbp_cond;
-static struct binheap *vbp_heap;
+static struct vbh *vbp_heap;

static const unsigned char vbp_proxy_local[] = {
0x0d, 0x0a, 0x0d, 0x0a, 0x00, 0x0d, 0x0a, 0x51,
@@ -417,8 +417,8 @@ static void
vbp_heap_insert(struct vbp_target *vt)
{
// Lck_AssertHeld(&vbp_mtx);
- binheap_insert(vbp_heap, vt);
- if (binheap_root(vbp_heap) == vt)
+ VBH_insert(vbp_heap, vt);
+ if (VBH_root(vbp_heap) == vt)
AZ(pthread_cond_signal(&vbp_cond));
}

@@ -444,13 +444,13 @@ vbp_task(struct worker *wrk, void *priv)

Lck_Lock(&vbp_mtx);
if (vt->running < 0) {
- assert(vt->heap_idx == BINHEAP_NOIDX);
+ assert(vt->heap_idx == VBH_NOIDX);
vbp_delete(vt);
} else {
vt->running = 0;
- if (vt->heap_idx != BINHEAP_NOIDX) {
+ if (vt->heap_idx != VBH_NOIDX) {
vt->due = VTIM_real() + vt->interval;
- binheap_delete(vbp_heap, vt->heap_idx);
+ VBH_delete(vbp_heap, vt->heap_idx);
vbp_heap_insert(vt);
}
}
@@ -472,7 +472,7 @@ vbp_thread(struct worker *wrk, void *priv)
Lck_Lock(&vbp_mtx);
while (1) {
now = VTIM_real();
- vt = binheap_root(vbp_heap);
+ vt = VBH_root(vbp_heap);
if (vt == NULL) {
nxt = 8.192 + now;
(void)Lck_CondWait(&vbp_cond, &vbp_mtx, nxt);
@@ -481,7 +481,7 @@ vbp_thread(struct worker *wrk, void *priv)
vt = NULL;
(void)Lck_CondWait(&vbp_cond, &vbp_mtx, nxt);
} else {
- binheap_delete(vbp_heap, vt->heap_idx);
+ VBH_delete(vbp_heap, vt->heap_idx);
vt->due = now + vt->interval;
if (!vt->running) {
vt->running = 1;
@@ -493,7 +493,7 @@ vbp_thread(struct worker *wrk, void *priv)
if (r)
vt->running = 0;
}
- binheap_insert(vbp_heap, vt);
+ VBH_insert(vbp_heap, vt);
}
}
NEEDLESS(Lck_Unlock(&vbp_mtx));
@@ -654,12 +654,12 @@ VBP_Control(const struct backend *be, int enable)

Lck_Lock(&vbp_mtx);
if (enable) {
- assert(vt->heap_idx == BINHEAP_NOIDX);
+ assert(vt->heap_idx == VBH_NOIDX);
vt->due = VTIM_real();
vbp_heap_insert(vt);
} else {
- assert(vt->heap_idx != BINHEAP_NOIDX);
- binheap_delete(vbp_heap, vt->heap_idx);
+ assert(vt->heap_idx != VBH_NOIDX);
+ VBH_delete(vbp_heap, vt->heap_idx);
}
Lck_Unlock(&vbp_mtx);
}
@@ -713,14 +713,14 @@ VBP_Remove(struct backend *be)
}
Lck_Unlock(&vbp_mtx);
if (vt != NULL) {
- assert(vt->heap_idx == BINHEAP_NOIDX);
+ assert(vt->heap_idx == VBH_NOIDX);
vbp_delete(vt);
}
}

/*-------------------------------------------------------------------*/

-static int v_matchproto_(binheap_cmp_t)
+static int v_matchproto_(vbh_cmp_t)
vbp_cmp(void *priv, const void *a, const void *b)
{
const struct vbp_target *aa, *bb;
@@ -739,7 +739,7 @@ vbp_cmp(void *priv, const void *a, const void *b)
return (aa->due < bb->due);
}

-static void v_matchproto_(binheap_update_t)
+static void v_matchproto_(vbh_update_t)
vbp_update(void *priv, void *p, unsigned u)
{
struct vbp_target *vt;
@@ -757,7 +757,7 @@ VBP_Init(void)
pthread_t thr;

Lck_New(&vbp_mtx, lck_probe);
- vbp_heap = binheap_new(NULL, vbp_cmp, vbp_update);
+ vbp_heap = VBH_new(NULL, vbp_cmp, vbp_update);
AN(vbp_heap);
AZ(pthread_cond_init(&vbp_cond, NULL));
WRK_BgThread(&thr, "backend-poller", vbp_thread, NULL);
diff --git a/bin/varnishd/cache/cache_expire.c b/bin/varnishd/cache/cache_expire.c
index ac3594629..85ee9ee1f 100644
--- a/bin/varnishd/cache/cache_expire.c
+++ b/bin/varnishd/cache/cache_expire.c
@@ -39,7 +39,7 @@
#include "cache_varnishd.h"
#include "cache_objhead.h"

-#include "binary_heap.h"
+#include "vbh.h"
#include "vtim.h"

struct exp_priv {
@@ -53,7 +53,7 @@ struct exp_priv {
/* owned by exp thread */
struct worker *wrk;
struct vsl_log vsl;
- struct binheap *heap;
+ struct vbh *heap;
pthread_t thread;
};

@@ -272,10 +272,10 @@ exp_inbox(struct exp_priv *ep, struct objcore *oc, unsigned flags)

if (flags & OC_EF_REMOVE) {
if (!(flags & OC_EF_INSERT)) {
- assert(oc->timer_idx != BINHEAP_NOIDX);
- binheap_delete(ep->heap, oc->timer_idx);
+ assert(oc->timer_idx != VBH_NOIDX);
+ VBH_delete(ep->heap, oc->timer_idx);
}
- assert(oc->timer_idx == BINHEAP_NOIDX);
+ assert(oc->timer_idx == VBH_NOIDX);
assert(oc->refcnt > 0);
AZ(oc->exp_flags);
ObjSendEvent(ep->wrk, oc, OEV_EXPIRE);
@@ -298,13 +298,13 @@ exp_inbox(struct exp_priv *ep, struct objcore *oc, unsigned flags)
*/

if (flags & OC_EF_INSERT) {
- assert(oc->timer_idx == BINHEAP_NOIDX);
- binheap_insert(exphdl->heap, oc);
- assert(oc->timer_idx != BINHEAP_NOIDX);
+ assert(oc->timer_idx == VBH_NOIDX);
+ VBH_insert(exphdl->heap, oc);
+ assert(oc->timer_idx != VBH_NOIDX);
} else if (flags & OC_EF_MOVE) {
- assert(oc->timer_idx != BINHEAP_NOIDX);
- binheap_reorder(exphdl->heap, oc->timer_idx);
- assert(oc->timer_idx != BINHEAP_NOIDX);
+ assert(oc->timer_idx != VBH_NOIDX);
+ VBH_reorder(exphdl->heap, oc->timer_idx);
+ assert(oc->timer_idx != VBH_NOIDX);
} else {
WRONG("Objcore state wrong in inbox");
}
@@ -321,7 +321,7 @@ exp_expire(struct exp_priv *ep, vtim_real now)

CHECK_OBJ_NOTNULL(ep, EXP_PRIV_MAGIC);

- oc = binheap_root(ep->heap);
+ oc = VBH_root(ep->heap);
if (oc == NULL)
return (now + 355./113.);
VSLb(&ep->vsl, SLT_ExpKill, "EXP_expire p=%p e=%.6f f=0x%x", oc,
@@ -348,9 +348,9 @@ exp_expire(struct exp_priv *ep, vtim_real now)
HSH_Kill(oc);

/* Remove from binheap */
- assert(oc->timer_idx != BINHEAP_NOIDX);
- binheap_delete(ep->heap, oc->timer_idx);
- assert(oc->timer_idx == BINHEAP_NOIDX);
+ assert(oc->timer_idx != VBH_NOIDX);
+ VBH_delete(ep->heap, oc->timer_idx);
+ assert(oc->timer_idx == VBH_NOIDX);

CHECK_OBJ_NOTNULL(oc->objhead, OBJHEAD_MAGIC);
VSLb(&ep->vsl, SLT_ExpKill, "EXP_Expired x=%u t=%.0f",
@@ -366,7 +366,7 @@ exp_expire(struct exp_priv *ep, vtim_real now)
* object expires, accounting also for graceability, it is killed.
*/

-static int v_matchproto_(binheap_cmp_t)
+static int v_matchproto_(vbh_cmp_t)
object_cmp(void *priv, const void *a, const void *b)
{
const struct objcore *aa, *bb;
@@ -377,7 +377,7 @@ object_cmp(void *priv, const void *a, const void *b)
return (aa->timer_when < bb->timer_when);
}

-static void v_matchproto_(binheap_update_t)
+static void v_matchproto_(vbh_update_t)
object_update(void *priv, void *p, unsigned u)
{
struct objcore *oc;
@@ -398,7 +398,7 @@ exp_thread(struct worker *wrk, void *priv)
CAST_OBJ_NOTNULL(ep, priv, EXP_PRIV_MAGIC);
ep->wrk = wrk;
VSL_Setup(&ep->vsl, NULL, 0);
- ep->heap = binheap_new(NULL, object_cmp, object_update);
+ ep->heap = VBH_new(NULL, object_cmp, object_update);
AN(ep->heap);
while (exp_shutdown == 0) {

diff --git a/bin/varnishd/flint.lnt b/bin/varnishd/flint.lnt
index 8d1867f6c..3caf03b01 100644
--- a/bin/varnishd/flint.lnt
+++ b/bin/varnishd/flint.lnt
@@ -151,7 +151,7 @@
-e441 // for clause irregularity: loop variable '___' not found in 2nd for expression

// from libvarnish
---emacro((835),BINHEAP_NOIDX)
+--emacro((835),VBH_NOIDX)
--emacro((835),O_CLOEXEC)

// Review all below this line ///////////////////////////////////////////////
diff --git a/bin/varnishd/waiter/cache_waiter.c b/bin/varnishd/waiter/cache_waiter.c
index 79de2cdef..0957f6ca8 100644
--- a/bin/varnishd/waiter/cache_waiter.c
+++ b/bin/varnishd/waiter/cache_waiter.c
@@ -36,13 +36,13 @@

#include <stdlib.h>

-#include "binary_heap.h"
+#include "vbh.h"

#include "waiter/waiter.h"
#include "waiter/waiter_priv.h"
#include "waiter/mgt_waiter.h"

-static int v_matchproto_(binheap_cmp_t)
+static int v_matchproto_(vbh_cmp_t)
waited_cmp(void *priv, const void *a, const void *b)
{
const struct waiter *ww;
@@ -55,7 +55,7 @@ waited_cmp(void *priv, const void *a, const void *b)
return (Wait_When(aa) < Wait_When(bb));
}

-static void v_matchproto_(binheap_update_t)
+static void v_matchproto_(vbh_update_t)
waited_update(void *priv, void *p, unsigned u)
{
struct waited *pp;
@@ -74,7 +74,7 @@ Wait_Call(const struct waiter *w, struct waited *wp,
CHECK_OBJ_NOTNULL(w, WAITER_MAGIC);
CHECK_OBJ_NOTNULL(wp, WAITED_MAGIC);
AN(wp->func);
- assert(wp->idx == BINHEAP_NOIDX);
+ assert(wp->idx == VBH_NOIDX);
wp->func(wp, ev, now);
}

@@ -85,8 +85,8 @@ Wait_HeapInsert(const struct waiter *w, struct waited *wp)
{
CHECK_OBJ_NOTNULL(w, WAITER_MAGIC);
CHECK_OBJ_NOTNULL(wp, WAITED_MAGIC);
- assert(wp->idx == BINHEAP_NOIDX);
- binheap_insert(w->heap, wp);
+ assert(wp->idx == VBH_NOIDX);
+ VBH_insert(w->heap, wp);
}

/*
@@ -102,9 +102,9 @@ Wait_HeapDelete(const struct waiter *w, const struct waited *wp)
{
CHECK_OBJ_NOTNULL(w, WAITER_MAGIC);
CHECK_OBJ_NOTNULL(wp, WAITED_MAGIC);
- if (wp->idx == BINHEAP_NOIDX)
+ if (wp->idx == VBH_NOIDX)
return (0);
- binheap_delete(w->heap, wp->idx);
+ VBH_delete(w->heap, wp->idx);
return (1);
}

@@ -113,7 +113,7 @@ Wait_HeapDue(const struct waiter *w, struct waited **wpp)
{
struct waited *wp;

- wp = binheap_root(w->heap);
+ wp = VBH_root(w->heap);
CHECK_OBJ_ORNULL(wp, WAITED_MAGIC);
if (wp == NULL) {
if (wpp != NULL)
@@ -135,7 +135,7 @@ Wait_Enter(const struct waiter *w, struct waited *wp)
CHECK_OBJ_NOTNULL(wp, WAITED_MAGIC);
assert(wp->fd > 0); // stdin never comes here
AN(wp->func);
- wp->idx = BINHEAP_NOIDX;
+ wp->idx = VBH_NOIDX;
return (w->impl->enter(w->priv, wp));
}

@@ -168,7 +168,7 @@ Waiter_New(void)
w->priv = (void*)(w + 1);
w->impl = waiter;
VTAILQ_INIT(&w->waithead);
- w->heap = binheap_new(w, waited_cmp, waited_update);
+ w->heap = VBH_new(w, waited_cmp, waited_update);

waiter->init(w);

@@ -182,7 +182,7 @@ Waiter_Destroy(struct waiter **wp)

TAKE_OBJ_NOTNULL(w, wp, WAITER_MAGIC);

- AZ(binheap_root(w->heap));
+ AZ(VBH_root(w->heap));
AN(w->impl->fini);
w->impl->fini(w);
FREE_OBJ(w);
diff --git a/bin/varnishd/waiter/waiter_priv.h b/bin/varnishd/waiter/waiter_priv.h
index ce8f93b4e..e44c548b9 100644
--- a/bin/varnishd/waiter/waiter_priv.h
+++ b/bin/varnishd/waiter/waiter_priv.h
@@ -32,7 +32,7 @@
*/

struct waited;
-struct binheap;
+struct vbh;

struct waiter {
unsigned magic;
@@ -42,7 +42,7 @@ struct waiter {
VTAILQ_HEAD(,waited) waithead;

void *priv;
- struct binheap *heap;
+ struct vbh *heap;
};

typedef void waiter_init_f(struct waiter *);
diff --git a/include/Makefile.am b/include/Makefile.am
index c344f593c..628993bf0 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -58,7 +58,7 @@ nobase_pkginclude_HEADERS = \

# Headers for use with vmods
nobase_pkginclude_HEADERS += \
- binary_heap.h \
+ vbh.h \
miniobj.h \
vas.h \
vav.h \
diff --git a/include/binary_heap.h b/include/vbh.h
similarity index 82%
rename from include/binary_heap.h
rename to include/vbh.h
index c9e39593c..2ac0f8565 100644
--- a/include/binary_heap.h
+++ b/include/vbh.h
@@ -35,16 +35,16 @@

/* Public Interface --------------------------------------------------*/

-struct binheap;
+struct vbh;

-typedef int binheap_cmp_t(void *priv, const void *a, const void *b);
+typedef int vbh_cmp_t(void *priv, const void *a, const void *b);
/*
* Comparison function.
* Should return true if item 'a' should be closer to the root
* than item 'b'
*/

-typedef void binheap_update_t(void *priv, void *a, unsigned newidx);
+typedef void vbh_update_t(void *priv, void *a, unsigned newidx);
/*
* Update function (optional)
* When items move in the tree, this function gets called to
@@ -52,36 +52,36 @@ typedef void binheap_update_t(void *priv, void *a, unsigned newidx);
* Only needed if deleting non-root items.
*/

-struct binheap *binheap_new(void *priv, binheap_cmp_t, binheap_update_t);
+struct vbh *VBH_new(void *priv, vbh_cmp_t, vbh_update_t);
/*
* Create Binary tree
* 'priv' is passed to cmp and update functions.
*/

-void binheap_destroy(struct binheap **);
+void VBH_destroy(struct vbh **);
/*
* Destroy an empty Binary tree
*/

-void binheap_insert(struct binheap *, void *);
+void VBH_insert(struct vbh *, void *);
/*
* Insert an item
*/

-void binheap_reorder(const struct binheap *, unsigned idx);
+void VBH_reorder(const struct vbh *, unsigned idx);
/*
* Move an order after changing its key value.
*/

-void binheap_delete(struct binheap *, unsigned idx);
+void VBH_delete(struct vbh *, unsigned idx);
/*
* Delete an item
* The root item has 'idx' zero
*/

-void *binheap_root(const struct binheap *);
+void *VBH_root(const struct vbh *);
/*
* Return the root item
*/

-#define BINHEAP_NOIDX 0
+#define VBH_NOIDX 0
diff --git a/lib/libvarnish/Makefile.am b/lib/libvarnish/Makefile.am
index 298d63400..4318d5734 100644
--- a/lib/libvarnish/Makefile.am
+++ b/lib/libvarnish/Makefile.am
@@ -15,7 +15,7 @@ libvarnish_la_CFLAGS = \
$(AM_CFLAGS)

libvarnish_la_SOURCES = \
- binary_heap.c \
+ vbh.c \
vas.c \
vav.c \
vcli_proto.c \
@@ -44,13 +44,13 @@ libvarnish_la_SOURCES = \
vtim.c \
vus.c

-TESTS = vjsn_test vnum_c_test binheap vsb_test
+TESTS = vjsn_test vnum_c_test vbh_test vsb_test

noinst_PROGRAMS = ${TESTS}

-binheap_SOURCES = binary_heap.c
-binheap_CFLAGS = $(AM_CFLAGS) -DTEST_DRIVER
-binheap_LDADD = $(AM_LDFLAGS) libvarnish.la
+vbh_test_SOURCES = vbh.c
+vbh_test_CFLAGS = $(AM_CFLAGS) -DTEST_DRIVER
+vbh_test_LDADD = $(AM_LDFLAGS) libvarnish.la

vnum_c_test_SOURCES = vnum.c
vnum_c_test_CFLAGS = $(AM_CFLAGS) -DNUM_C_TEST
diff --git a/lib/libvarnish/flint.lnt b/lib/libvarnish/flint.lnt
index 775226510..eaf3e61b5 100644
--- a/lib/libvarnish/flint.lnt
+++ b/lib/libvarnish/flint.lnt
@@ -8,5 +8,5 @@

-dVARNISH_STATE_DIR="foo"

---emacro((835),BINHEAP_NOIDX)
+--emacro((835),VBH_NOIDX)
--emacro((835),O_CLOEXEC)
diff --git a/lib/libvarnish/binary_heap.c b/lib/libvarnish/vbh.c
similarity index 83%
rename from lib/libvarnish/binary_heap.c
rename to lib/libvarnish/vbh.c
index 0896ed14c..b8417eb87 100644
--- a/lib/libvarnish/binary_heap.c
+++ b/lib/libvarnish/vbh.c
@@ -45,7 +45,7 @@
#include "miniobj.h"
#include "vdef.h"
#include "vas.h"
-#include "binary_heap.h"
+#include "vbh.h"

#if !defined(__has_feature)
#define __has_feature(x) 0
@@ -82,12 +82,12 @@
/*lint -emacro(835, A) 0 left of & */
#define A(b, n) ROW(b, n)[(n) & (ROW_WIDTH - 1)]

-struct binheap {
+struct vbh {
unsigned magic;
-#define BINHEAP_MAGIC 0xf581581aU /* from /dev/random */
+#define VBH_MAGIC 0xf581581aU /* from /dev/random */
void *priv;
- binheap_cmp_t *cmp;
- binheap_update_t *update;
+ vbh_cmp_t *cmp;
+ vbh_update_t *update;
void ***array;
unsigned rows;
unsigned length;
@@ -102,7 +102,7 @@ struct binheap {
#ifdef VM_AWARE

static unsigned
-parent(const struct binheap *bh, unsigned u)
+parent(const struct vbh *bh, unsigned u)
{
unsigned po;
unsigned v;
@@ -123,7 +123,7 @@ parent(const struct binheap *bh, unsigned u)
}

static void
-child(const struct binheap *bh, unsigned u, unsigned *a, unsigned *b)
+child(const struct vbh *bh, unsigned u, unsigned *a, unsigned *b)
{
uintmax_t uu;

@@ -168,7 +168,7 @@ child(const struct binheap *bh, unsigned u, unsigned *a, unsigned *b)
#else

static unsigned
-parent(const struct binheap *bh, unsigned u)
+parent(const struct vbh *bh, unsigned u)
{

(void)bh;
@@ -176,7 +176,7 @@ parent(const struct binheap *bh, unsigned u)
}

static void
-child(const struct binheap *bh, unsigned u, unsigned *a, unsigned *b)
+child(const struct vbh *bh, unsigned u, unsigned *a, unsigned *b)
{

(void)bh;
@@ -189,7 +189,7 @@ child(const struct binheap *bh, unsigned u, unsigned *a, unsigned *b)
/* Implementation ----------------------------------------------------*/

static void
-binheap_addrow(struct binheap *bh)
+vbh_addrow(struct vbh *bh)
{
unsigned u;

@@ -209,13 +209,13 @@ binheap_addrow(struct binheap *bh)
bh->length += ROW_WIDTH;
}

-struct binheap *
-binheap_new(void *priv, binheap_cmp_t *cmp_f, binheap_update_t *update_f)
+struct vbh *
+VBH_new(void *priv, vbh_cmp_t *cmp_f, vbh_update_t *update_f)
{
- struct binheap *bh;
+ struct vbh *bh;
unsigned u;

- ALLOC_OBJ(bh, BINHEAP_MAGIC);
+ ALLOC_OBJ(bh, VBH_MAGIC);
if (bh == NULL)
return (bh);
bh->priv = priv;
@@ -238,20 +238,20 @@ binheap_new(void *priv, binheap_cmp_t *cmp_f, binheap_update_t *update_f)
#endif
bh->array = calloc(bh->rows, sizeof *bh->array);
assert(bh->array != NULL);
- binheap_addrow(bh);
+ vbh_addrow(bh);
A(bh, ROOT_IDX) = NULL;
- bh->magic = BINHEAP_MAGIC;
+ bh->magic = VBH_MAGIC;
return (bh);
}

void
-binheap_destroy(struct binheap **bhp)
+VBH_destroy(struct vbh **bhp)
{
- struct binheap *bh;
+ struct vbh *bh;
unsigned u;

- TAKE_OBJ_NOTNULL(bh, bhp, BINHEAP_MAGIC);
- AZ(binheap_root(bh));
+ TAKE_OBJ_NOTNULL(bh, bhp, VBH_MAGIC);
+ AZ(VBH_root(bh));

for (u = 0; u < bh->length; u += ROW_WIDTH)
free(ROW(bh, u));
@@ -260,9 +260,9 @@ binheap_destroy(struct binheap **bhp)
}

static void
-binheap_update(const struct binheap *bh, unsigned u)
+vbh_update(const struct vbh *bh, unsigned u)
{
- CHECK_OBJ_NOTNULL(bh, BINHEAP_MAGIC);
+ CHECK_OBJ_NOTNULL(bh, VBH_MAGIC);
assert(u < bh->next);
assert(A(bh, u) != NULL);
if (bh->update != NULL)
@@ -270,11 +270,11 @@ binheap_update(const struct binheap *bh, unsigned u)
}

static void
-binhead_swap(const struct binheap *bh, unsigned u, unsigned v)
+binhead_swap(const struct vbh *bh, unsigned u, unsigned v)
{
void *p;

- CHECK_OBJ_NOTNULL(bh, BINHEAP_MAGIC);
+ CHECK_OBJ_NOTNULL(bh, VBH_MAGIC);
assert(u < bh->next);
assert(A(bh, u) != NULL);
assert(v < bh->next);
@@ -282,16 +282,16 @@ binhead_swap(const struct binheap *bh, unsigned u, unsigned v)
p = A(bh, u);
A(bh, u) = A(bh, v);
A(bh, v) = p;
- binheap_update(bh, u);
- binheap_update(bh, v);
+ vbh_update(bh, u);
+ vbh_update(bh, v);
}

static unsigned
-binheap_trickleup(const struct binheap *bh, unsigned u)
+vbh_trickleup(const struct vbh *bh, unsigned u)
{
unsigned v;

- CHECK_OBJ_NOTNULL(bh, BINHEAP_MAGIC);
+ CHECK_OBJ_NOTNULL(bh, VBH_MAGIC);
assert(u < bh->next);
assert(A(bh, u) != NULL);

@@ -311,11 +311,11 @@ binheap_trickleup(const struct binheap *bh, unsigned u)
}

static unsigned
-binheap_trickledown(const struct binheap *bh, unsigned u)
+vbh_trickledown(const struct vbh *bh, unsigned u)
{
unsigned v1, v2;

- CHECK_OBJ_NOTNULL(bh, BINHEAP_MAGIC);
+ CHECK_OBJ_NOTNULL(bh, VBH_MAGIC);
assert(u < bh->next);
assert(A(bh, u) != NULL);

@@ -346,19 +346,19 @@ binheap_trickledown(const struct binheap *bh, unsigned u)
}

void
-binheap_insert(struct binheap *bh, void *p)
+VBH_insert(struct vbh *bh, void *p)
{
unsigned u;

- CHECK_OBJ_NOTNULL(bh, BINHEAP_MAGIC);
+ CHECK_OBJ_NOTNULL(bh, VBH_MAGIC);
assert(bh->length >= bh->next);
if (bh->length == bh->next)
- binheap_addrow(bh);
+ vbh_addrow(bh);
assert(bh->length > bh->next);
u = bh->next++;
A(bh, u) = p;
- binheap_update(bh, u);
- (void)binheap_trickleup(bh, u);
+ vbh_update(bh, u);
+ (void)vbh_trickleup(bh, u);
assert(u < bh->next);
assert(A(bh, u) != NULL);
}
@@ -366,7 +366,7 @@ binheap_insert(struct binheap *bh, void *p)

#ifdef PARANOIA
static void
-chk(const struct binheap *bh)
+chk(const struct vbh *bh)
{
unsigned u, v;

@@ -378,10 +378,10 @@ chk(const struct binheap *bh)
#endif

void *
-binheap_root(const struct binheap *bh)
+VBH_root(const struct vbh *bh)
{

- CHECK_OBJ_NOTNULL(bh, BINHEAP_MAGIC);
+ CHECK_OBJ_NOTNULL(bh, VBH_MAGIC);
#ifdef PARANOIA
chk(bh);
#endif
@@ -413,27 +413,27 @@ binheap_root(const struct binheap *bh)
*/

void
-binheap_delete(struct binheap *bh, unsigned idx)
+VBH_delete(struct vbh *bh, unsigned idx)
{

- CHECK_OBJ_NOTNULL(bh, BINHEAP_MAGIC);
+ CHECK_OBJ_NOTNULL(bh, VBH_MAGIC);
assert(bh->next > ROOT_IDX);
assert(idx < bh->next);
assert(idx > 0);
assert(A(bh, idx) != NULL);
- bh->update(bh->priv, A(bh, idx), BINHEAP_NOIDX);
+ bh->update(bh->priv, A(bh, idx), VBH_NOIDX);
if (idx == --bh->next) {
A(bh, bh->next) = NULL;
return;
}
A(bh, idx) = A(bh, bh->next);
A(bh, bh->next) = NULL;
- binheap_update(bh, idx);
- idx = binheap_trickleup(bh, idx);
+ vbh_update(bh, idx);
+ idx = vbh_trickleup(bh, idx);
assert(idx < bh->next);
assert(idx > 0);
assert(A(bh, idx) != NULL);
- idx = binheap_trickledown(bh, idx);
+ idx = vbh_trickledown(bh, idx);
assert(idx < bh->next);
assert(idx > 0);
assert(A(bh, idx) != NULL);
@@ -455,19 +455,19 @@ binheap_delete(struct binheap *bh, unsigned idx)
*/

void
-binheap_reorder(const struct binheap *bh, unsigned idx)
+VBH_reorder(const struct vbh *bh, unsigned idx)
{

- CHECK_OBJ_NOTNULL(bh, BINHEAP_MAGIC);
+ CHECK_OBJ_NOTNULL(bh, VBH_MAGIC);
assert(bh->next > ROOT_IDX);
assert(idx < bh->next);
assert(idx > 0);
assert(A(bh, idx) != NULL);
- idx = binheap_trickleup(bh, idx);
+ idx = vbh_trickleup(bh, idx);
assert(idx < bh->next);
assert(idx > 0);
assert(A(bh, idx) != NULL);
- idx = binheap_trickledown(bh, idx);
+ idx = vbh_trickledown(bh, idx);
assert(idx < bh->next);
assert(idx > 0);
assert(A(bh, idx) != NULL);
@@ -496,7 +496,7 @@ struct foo {

struct foo *ff[N];

-static int v_matchproto_(binheap_cmp_t)
+static int v_matchproto_(vbh_cmp_t)
cmp(void *priv, const void *a, const void *b)
{
const struct foo *fa, *fb;
@@ -507,7 +507,7 @@ cmp(void *priv, const void *a, const void *b)
return (fa->key < fb->key);
}

-static void v_matchproto_(binheap_update_t)
+static void v_matchproto_(vbh_update_t)
update(void *priv, void *a, unsigned u)
{
struct foo *fa;
@@ -519,7 +519,7 @@ update(void *priv, void *a, unsigned u)

#ifdef CHECK2
static void
-chk2(struct binheap *bh)
+chk2(struct vbh *bh)
{
unsigned u, v;
struct foo *fa, *fb;
@@ -541,7 +541,7 @@ vrnd_lock(void)
int
main(void)
{
- struct binheap *bh;
+ struct vbh *bh;
unsigned j, u, v, lr, n;
struct foo *fp;

@@ -550,7 +550,7 @@ main(void)
VRND_Lock = vrnd_lock;
VRND_Unlock = vrnd_lock;

- bh = binheap_new(NULL, cmp, update);
+ bh = VBH_new(NULL, cmp, update);
for (n = 2; n; n += n) {
child(bh, n - 1, &u, &v);
child(bh, n, &u, &v);
@@ -567,16 +567,16 @@ main(void)
assert(ff[u] != NULL);
ff[u]->key = lr;
ff[u]->n = u;
- binheap_insert(bh, ff[u]);
+ VBH_insert(bh, ff[u]);

- fp = binheap_root(bh);
+ fp = VBH_root(bh);
assert(fp->idx == 1);
assert(fp->key <= lr);
}
fprintf(stderr, "%d inserts OK\n", N);
/* For M cycles, pick the root, insert new */
for (u = 0; u < M; u++) {
- fp = binheap_root(bh);
+ fp = VBH_root(bh);
CHECK_OBJ_NOTNULL(fp, FOO_MAGIC);
assert(fp->idx == 1);

@@ -585,7 +585,7 @@ main(void)
* value we added
*/
assert(fp->key <= lr);
- binheap_delete(bh, fp->idx);
+ VBH_delete(bh, fp->idx);

n = fp->n;
ALLOC_OBJ(ff[n], FOO_MAGIC);
@@ -596,18 +596,18 @@ main(void)

lr = VRND_RandomTestable() % R;
fp->key = lr;
- binheap_insert(bh, fp);
+ VBH_insert(bh, fp);
}
fprintf(stderr, "%d replacements OK\n", M);
/* The remove everything */
lr = 0;
for (u = 0; u < N; u++) {
- fp = binheap_root(bh);
+ fp = VBH_root(bh);
CHECK_OBJ_NOTNULL(fp, FOO_MAGIC);
assert(fp->idx == 1);
assert(fp->key >= lr);
lr = fp->key;
- binheap_delete(bh, fp->idx);
+ VBH_delete(bh, fp->idx);
ff[fp->n] = NULL;
FREE_OBJ(fp);
}
@@ -619,19 +619,19 @@ main(void)
CHECK_OBJ_NOTNULL(ff[v], FOO_MAGIC);
AN(ff[v]->idx);
if (ff[v]->key & 1) {
- binheap_delete(bh, ff[v]->idx);
- assert(ff[v]->idx == BINHEAP_NOIDX);
+ VBH_delete(bh, ff[v]->idx);
+ assert(ff[v]->idx == VBH_NOIDX);
FREE_OBJ(ff[v]);
ff[v] = NULL;
} else {
ff[v]->key = VRND_RandomTestable() % R;
- binheap_reorder(bh, ff[v]->idx);
+ VBH_reorder(bh, ff[v]->idx);
}
} else {
ALLOC_OBJ(ff[v], FOO_MAGIC);
assert(ff[v] != NULL);
ff[v]->key = VRND_RandomTestable() % R;
- binheap_insert(bh, ff[v]);
+ VBH_insert(bh, ff[v]);
CHECK_OBJ_NOTNULL(ff[v], FOO_MAGIC);
AN(ff[v]->idx);
}
@@ -641,11 +641,11 @@ main(void)
}
fprintf(stderr, "%d updates OK\n", M);
}
- while ((fp = binheap_root(bh)) != NULL) {
- binheap_delete(bh, fp->idx);
+ while ((fp = VBH_root(bh)) != NULL) {
+ VBH_delete(bh, fp->idx);
FREE_OBJ(fp);
}
- binheap_destroy(&bh);
+ VBH_destroy(&bh);
AZ(bh);
return (0);
}
diff --git a/lib/libvarnish/vev.c b/lib/libvarnish/vev.c
index ac8fd4d4f..f6359d38f 100644
--- a/lib/libvarnish/vev.c
+++ b/lib/libvarnish/vev.c
@@ -43,7 +43,7 @@
#include "miniobj.h"
#include "vas.h"

-#include "binary_heap.h"
+#include "vbh.h"
#include "vev.h"
#include "vtim.h"

@@ -71,7 +71,7 @@ struct vev_root {
struct vev **pev;
unsigned npfd;
unsigned lpfd;
- struct binheap *binheap;
+ struct vbh *binheap;
unsigned psig;
pthread_t thread;
#ifdef DEBUG_EVENTS
@@ -93,7 +93,7 @@ struct vev_root {

/*--------------------------------------------------------------------*/

-static void v_matchproto_(binheap_update_t)
+static void v_matchproto_(vbh_update_t)
vev_bh_update(void *priv, void *a, unsigned u)
{
struct vev_root *evb;
@@ -103,7 +103,7 @@ vev_bh_update(void *priv, void *a, unsigned u)
CAST_OBJ_NOTNULL(e, a, VEV_MAGIC);
assert(u < evb->lpfd);
e->__binheap_idx = u;
- if (u != BINHEAP_NOIDX) {
+ if (u != VBH_NOIDX) {
evb->pev[u] = e;
evb->pfd[u].fd = e->fd;
evb->pfd[u].events =
@@ -111,7 +111,7 @@ vev_bh_update(void *priv, void *a, unsigned u)
}
}

-static int v_matchproto_(binheap_cmp_t)
+static int v_matchproto_(vbh_cmp_t)
vev_bh_cmp(void *priv, const void *a, const void *b)
{
struct vev_root *evb;
@@ -196,13 +196,13 @@ VEV_New(void)
evb = calloc(1, sizeof *evb);
if (evb == NULL)
return (evb);
- evb->lpfd = BINHEAP_NOIDX + 1;
+ evb->lpfd = VBH_NOIDX + 1;
if (vev_get_pfd(evb)) {
free(evb);
return (NULL);
}
evb->magic = VEV_BASE_MAGIC;
- evb->binheap = binheap_new(evb, vev_bh_cmp, vev_bh_update);
+ evb->binheap = VBH_new(evb, vev_bh_cmp, vev_bh_update);
evb->thread = pthread_self();
#ifdef DEBUG_EVENTS
evb->debug = fopen("/tmp/_.events", "w");
@@ -278,7 +278,7 @@ VEV_Start(struct vev_root *evb, struct vev *e)
es = NULL;
}

- e->magic = VEV_MAGIC; /* before binheap_insert() */
+ e->magic = VEV_MAGIC; /* before VBH_insert() */

if (e->timeout != 0.0)
e->__when += VTIM_mono() + e->timeout;
@@ -286,8 +286,8 @@ VEV_Start(struct vev_root *evb, struct vev *e)
e->__when = 9e99;

evb->lpfd++;
- binheap_insert(evb->binheap, e);
- assert(e->__binheap_idx != BINHEAP_NOIDX);
+ VBH_insert(evb->binheap, e);
+ assert(e->__binheap_idx != VBH_NOIDX);

e->__vevb = evb;
e->__privflags = 0;
@@ -314,10 +314,10 @@ VEV_Stop(struct vev_root *evb, struct vev *e)
assert(evb->thread == pthread_self());
assert(evb->pev[e->__binheap_idx] == e);

- assert(e->__binheap_idx != BINHEAP_NOIDX);
+ assert(e->__binheap_idx != VBH_NOIDX);
e->fd = -1;
- binheap_delete(evb->binheap, e->__binheap_idx);
- assert(e->__binheap_idx == BINHEAP_NOIDX);
+ VBH_delete(evb->binheap, e->__binheap_idx);
+ assert(e->__binheap_idx == VBH_NOIDX);
evb->lpfd--;

if (e->sig > 0) {
@@ -365,8 +365,8 @@ vev_sched_timeout(struct vev_root *evb, struct vev *e, vtim_mono t)
free(e);
} else {
e->__when = t + e->timeout;
- binheap_delete(evb->binheap, e->__binheap_idx);
- binheap_insert(evb->binheap, e);
+ VBH_delete(evb->binheap, e->__binheap_idx);
+ VBH_insert(evb->binheap, e);
}
return (1);
}
@@ -413,10 +413,10 @@ VEV_Once(struct vev_root *evb)
return (vev_sched_signal(evb));

tmo = INFTIM;
- e = binheap_root(evb->binheap);
+ e = VBH_root(evb->binheap);
if (e != NULL) {
CHECK_OBJ(e, VEV_MAGIC);
- assert(e->__binheap_idx == BINHEAP_NOIDX + 1);
+ assert(e->__binheap_idx == VBH_NOIDX + 1);
t = VTIM_mono();
if (e->__when <= t)
return (vev_sched_timeout(evb, e, t));
@@ -426,7 +426,7 @@ VEV_Once(struct vev_root *evb)
tmo = 1;
}

- if (tmo == INFTIM && evb->lpfd == BINHEAP_NOIDX + 1)
+ if (tmo == INFTIM && evb->lpfd == VBH_NOIDX + 1)
return (0);

i = poll(evb->pfd + 1, evb->lpfd - 1, tmo);
@@ -452,7 +452,7 @@ VEV_Once(struct vev_root *evb)

DBG(evb, "EVENTS %d\n", i);
while (i > 0) {
- for (u = BINHEAP_NOIDX + 1; u < evb->lpfd; u++) {
+ for (u = VBH_NOIDX + 1; u < evb->lpfd; u++) {
e = evb->pev[u];
if (e->fd_events == 0)
continue;
diff --git a/tools/lsan.suppr b/tools/lsan.suppr
index 8ed7048df..f9ca2be93 100644
--- a/tools/lsan.suppr
+++ b/tools/lsan.suppr
@@ -9,7 +9,7 @@ leak:vcc_
leak:VSL_Setup
leak:WRK_BgThread
#
-leak:binheap_new
+leak:VBH_new
# ev
leak:mct_callback
#
_______________________________________________
varnish-commit mailing list
varnish-commit@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-commit