rename binheap / binary_heap -> vbh

with the public api functions called VBH_
parent c676ca46
......@@ -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);
......
......@@ -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) {
......
......@@ -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 ///////////////////////////////////////////////
......
......@@ -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);
......
......@@ -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 *);
......
......@@ -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 \
......
......@@ -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
......@@ -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
......
......@@ -8,5 +8,5 @@
-dVARNISH_STATE_DIR="foo"
--emacro((835),BINHEAP_NOIDX)
--emacro((835),VBH_NOIDX)
--emacro((835),O_CLOEXEC)
......@@ -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;
......
......@@ -9,7 +9,7 @@ leak:vcc_
leak:VSL_Setup
leak:WRK_BgThread
#
leak:binheap_new
leak:VBH_new
# ev
leak:mct_callback
#
......
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