[master] de4d412 Eliminate the waitfor structure.
Poul-Henning Kamp
phk at FreeBSD.org
Fri Jan 27 11:18:05 CET 2017
commit de4d41219297c1ad289718fc0e30c025aeb96cf2
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Fri Jan 27 10:17:33 2017 +0000
Eliminate the waitfor structure.
diff --git a/bin/varnishd/cache/cache_backend_tcp.c b/bin/varnishd/cache/cache_backend_tcp.c
index fdabe6f..425a7de 100644
--- a/bin/varnishd/cache/cache_backend_tcp.c
+++ b/bin/varnishd/cache/cache_backend_tcp.c
@@ -59,8 +59,6 @@ struct tcp_pool {
int refcnt;
struct lock mtx;
- struct waitfor waitfor;
-
VTAILQ_HEAD(, vbc) connlist;
int n_conn;
@@ -162,9 +160,6 @@ VBT_Ref(const struct suckaddr *ip4, const struct suckaddr *ip6)
VTAILQ_INIT(&tp->connlist);
VTAILQ_INIT(&tp->killlist);
VTAILQ_INSERT_HEAD(&pools, tp, list);
- INIT_OBJ(&tp->waitfor, WAITFOR_MAGIC);
- tp->waitfor.func = tcp_handle;
- tp->waitfor.tmo = &cache_param->backend_idle_timeout;
return (tp);
}
@@ -265,7 +260,8 @@ VBT_Recycle(const struct worker *wrk, struct tcp_pool *tp, struct vbc **vbcp)
vbc->waited->fd = vbc->fd;
vbc->waited->idle = VTIM_real();
vbc->state = VBC_STATE_AVAIL;
- vbc->waited->waitfor = &tp->waitfor;
+ vbc->waited->func = tcp_handle;
+ vbc->waited->tmo = &cache_param->backend_idle_timeout;
if (Wait_Enter(wrk->pool->waiter, vbc->waited)) {
VTCP_close(&vbc->fd);
memset(vbc, 0x33, sizeof *vbc);
diff --git a/bin/varnishd/cache/cache_pool.h b/bin/varnishd/cache/cache_pool.h
index fa3663a..83359ce 100644
--- a/bin/varnishd/cache/cache_pool.h
+++ b/bin/varnishd/cache/cache_pool.h
@@ -51,7 +51,6 @@ struct pool {
struct dstat *a_stat;
struct dstat *b_stat;
- struct waitfor wf;
struct mempool *mpl_req;
struct mempool *mpl_sess;
struct waiter *waiter;
diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c
index cc148b3..20a2844 100644
--- a/bin/varnishd/cache/cache_session.c
+++ b/bin/varnishd/cache/cache_session.c
@@ -455,7 +455,8 @@ SES_Wait(struct sess *sp, const struct transport *xp)
wp->priv1 = sp;
wp->priv2 = (uintptr_t)xp;
wp->idle = sp->t_idle;
- wp->waitfor = &pp->wf;
+ wp->func = ses_handle;
+ wp->tmo = &cache_param->timeout_idle;
if (Wait_Enter(pp->waiter, wp))
SES_Delete(sp, SC_PIPE_OVERFLOW, NAN);
}
@@ -594,8 +595,5 @@ SES_NewPool(struct pool *pp, unsigned pool_no)
pp->mpl_sess = MPL_New(nb, &cache_param->sess_pool,
&cache_param->workspace_session);
- INIT_OBJ(&pp->wf, WAITFOR_MAGIC);
- pp->wf.func = ses_handle;
- pp->wf.tmo = &cache_param->timeout_idle;
pp->waiter = Waiter_New();
}
diff --git a/bin/varnishd/waiter/cache_waiter.c b/bin/varnishd/waiter/cache_waiter.c
index 2d31d36..28f50b1 100644
--- a/bin/varnishd/waiter/cache_waiter.c
+++ b/bin/varnishd/waiter/cache_waiter.c
@@ -71,10 +71,9 @@ Wait_Call(const struct waiter *w, struct waited *wp,
{
CHECK_OBJ_NOTNULL(w, WAITER_MAGIC);
CHECK_OBJ_NOTNULL(wp, WAITED_MAGIC);
- CHECK_OBJ_NOTNULL(wp->waitfor, WAITFOR_MAGIC);
- AN(wp->waitfor->func);
+ AN(wp->func);
assert(wp->idx == BINHEAP_NOIDX);
- wp->waitfor->func(wp, ev, now);
+ wp->func(wp, ev, now);
}
/**********************************************************************/
@@ -133,7 +132,8 @@ Wait_Enter(const struct waiter *w, struct waited *wp)
CHECK_OBJ_NOTNULL(w, WAITER_MAGIC);
CHECK_OBJ_NOTNULL(wp, WAITED_MAGIC);
assert(wp->fd > 0); // stdin never comes here
- CHECK_OBJ_NOTNULL(wp->waitfor, WAITFOR_MAGIC);
+ AN(wp->func);
+ AN(wp->tmo);
wp->idx = BINHEAP_NOIDX;
return (w->impl->enter(w->priv, wp));
}
diff --git a/bin/varnishd/waiter/waiter.h b/bin/varnishd/waiter/waiter.h
index 4cbabb6..531f640 100644
--- a/bin/varnishd/waiter/waiter.h
+++ b/bin/varnishd/waiter/waiter.h
@@ -54,13 +54,6 @@ enum wait_event {
typedef void waiter_handle_f(struct waited *, enum wait_event, double now);
-struct waitfor {
- unsigned magic;
-#define WAITFOR_MAGIC 0x16b79246
- waiter_handle_f *func;
- volatile double *tmo;
-};
-
struct waited {
unsigned magic;
#define WAITED_MAGIC 0x1743992d
@@ -68,7 +61,8 @@ struct waited {
unsigned idx;
void *priv1;
uintptr_t priv2;
- const struct waitfor *waitfor;
+ waiter_handle_f *func;
+ volatile double *tmo;
double idle;
};
diff --git a/bin/varnishd/waiter/waiter_priv.h b/bin/varnishd/waiter/waiter_priv.h
index 6db06ca..502d349 100644
--- a/bin/varnishd/waiter/waiter_priv.h
+++ b/bin/varnishd/waiter/waiter_priv.h
@@ -62,17 +62,16 @@ static inline double
Wait_Tmo(const struct waited *wp)
{
CHECK_OBJ_ORNULL(wp, WAITED_MAGIC);
- CHECK_OBJ_NOTNULL(wp->waitfor, WAITFOR_MAGIC);
- AN(wp->waitfor->tmo);
- return (*wp->waitfor->tmo);
+ AN(wp->tmo);
+ return (*wp->tmo);
}
static inline double
Wait_When(const struct waited *wp)
{
CHECK_OBJ_ORNULL(wp, WAITED_MAGIC);
- CHECK_OBJ_NOTNULL(wp->waitfor, WAITFOR_MAGIC);
- return (wp->idle + *wp->waitfor->tmo);
+ AN(wp->tmo);
+ return (wp->idle + *wp->tmo);
}
void Wait_Call(const struct waiter *, struct waited *,
More information about the varnish-commit
mailing list