Commit 6109c1d4 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Pass pointer to the timeout variable into the waiter on creation.

parent d6ef2cdb
......@@ -467,7 +467,7 @@ SES_NewPool(struct pool *wp, unsigned pool_no)
bprintf(nb, "sess%u", pool_no);
pp->mpl_sess = MPL_New(nb, &cache_param->sess_pool,
&cache_param->workspace_session);
pp->http1_waiter = WAIT_Init(ses_handle);
pp->http1_waiter = WAIT_Init(ses_handle, &cache_param->timeout_idle);
return (pp);
}
......
......@@ -58,7 +58,7 @@ WAIT_GetName(void)
}
struct waiter *
WAIT_Init(waiter_handle_f *func)
WAIT_Init(waiter_handle_f *func, volatile double *tmo)
{
struct waiter *w;
......@@ -70,7 +70,7 @@ WAIT_Init(waiter_handle_f *func)
AN(waiter->name);
AN(waiter->init);
w->impl = waiter;
w->priv = w->impl->init(func, &w->pfd);
w->priv = w->impl->init(func, &w->pfd, tmo);
AN(waiter->pass || w->pfd >= 0);
return (w);
}
......
......@@ -60,6 +60,7 @@ struct vwe {
int epfd;
waiter_handle_f *func;
volatile double *tmo;
VTAILQ_HEAD(,waited) sesshead;
int pipes[2];
......@@ -178,7 +179,7 @@ vwe_thread(void *priv)
continue;
/* check for timeouts */
deadline = now - cache_param->timeout_idle;
deadline = now - *vwe->tmo;
for (;;) {
sp = VTAILQ_FIRST(&vwe->sesshead);
if (sp == NULL)
......@@ -186,7 +187,6 @@ vwe_thread(void *priv)
if (sp->deadline > deadline)
break;
VTAILQ_REMOVE(&vwe->sesshead, sp, list);
// XXX: not yet VTCP_linger(sp->fd, 0);
vwe->func(sp, WAITER_TIMEOUT, now);
}
}
......@@ -215,14 +215,17 @@ vwe_timeout_idle_ticker(void *priv)
/*--------------------------------------------------------------------*/
static void * __match_proto__(waiter_init_f)
vwe_init(waiter_handle_f *func, int *pfd)
vwe_init(waiter_handle_f *func, int *pfd, volatile double *tmo)
{
struct vwe *vwe;
AN(func);
AN(pfd);
AN(tmo);
ALLOC_OBJ(vwe, VWE_MAGIC);
AN(vwe);
VTAILQ_INIT(&vwe->sesshead);
AZ(pipe(vwe->pipes));
AZ(pipe(vwe->timer_pipes));
......@@ -232,6 +235,7 @@ vwe_init(waiter_handle_f *func, int *pfd)
AZ(VFIL_nonblocking(vwe->timer_pipes[0]));
vwe->func = func;
vwe->tmo = tmo;
*pfd = vwe->pipes[1];
AZ(pthread_create(&vwe->timer_thread,
......
......@@ -53,6 +53,7 @@ struct vwk {
unsigned magic;
#define VWK_MAGIC 0x1cc2acc2
waiter_handle_f *func;
volatile double *tmo;
pthread_t thread;
int pipes[2];
int kq;
......@@ -192,7 +193,7 @@ vwk_thread(void *priv)
* would not know we meant "the old fd of this number".
*/
vwk_kq_flush(vwk);
deadline = now - cache_param->timeout_idle;
deadline = now - *vwk->tmo;
for (;;) {
sp = VTAILQ_FIRST(&vwk->sesshead);
if (sp == NULL)
......@@ -210,16 +211,18 @@ vwk_thread(void *priv)
/*--------------------------------------------------------------------*/
static void * __match_proto__(waiter_init_f)
vwk_init(waiter_handle_f *func, int *pfd)
vwk_init(waiter_handle_f *func, int *pfd, volatile double *tmo)
{
struct vwk *vwk;
AN(func);
AN(pfd);
AN(tmo);
ALLOC_OBJ(vwk, VWK_MAGIC);
AN(vwk);
vwk->func = func;
vwk->tmo = tmo;
VTAILQ_INIT(&vwk->sesshead);
AZ(pipe(vwk->pipes));
......
......@@ -46,6 +46,7 @@ struct vwp {
unsigned magic;
#define VWP_MAGIC 0x4b2cc735
waiter_handle_f *func;
volatile double *tmo;
int pipes[2];
pthread_t poll_thread;
struct pollfd *pollfd;
......@@ -144,7 +145,7 @@ vwp_main(void *priv)
v = poll(vwp->pollfd, vwp->hpoll + 1, 100);
assert(v >= 0);
now = VTIM_real();
deadline = now - cache_param->timeout_idle;
deadline = now - *vwp->tmo;
v2 = v;
VTAILQ_FOREACH_SAFE(sp, &vwp->sesshead, list, sp2) {
if (v != 0 && v2 == 0)
......@@ -194,7 +195,7 @@ vwp_main(void *priv)
/*--------------------------------------------------------------------*/
static void * __match_proto__(waiter_init_f)
vwp_poll_init(waiter_handle_f *func, int *pfd)
vwp_poll_init(waiter_handle_f *func, int *pfd, volatile double *tmo)
{
struct vwp *vwp;
......@@ -206,6 +207,7 @@ vwp_poll_init(waiter_handle_f *func, int *pfd)
AZ(pipe(vwp->pipes));
vwp->func = func;
vwp->tmo = tmo;
AZ(VFIL_nonblocking(vwp->pipes[1]));
*pfd = vwp->pipes[1];
......
......@@ -51,6 +51,7 @@ struct vws {
unsigned magic;
#define VWS_MAGIC 0x0b771473
waiter_handle_f *func;
volatile double *tmo;
pthread_t ports_thread;
int dport;
VTAILQ_HEAD(,waited) sesshead;
......@@ -192,7 +193,7 @@ vws_thread(void *priv)
vws_port_ev(vws, ev + ei, now);
/* check for timeouts */
deadline = now - cache_param->timeout_idle;
deadline = now - *vwk->tmo;
/*
* This loop assumes that the oldest sessions are always at the
......@@ -220,8 +221,7 @@ vws_thread(void *priv)
*/
if (sp) {
double tmo =
(sp->deadline + cache_param->timeout_idle) - now;
double tmo = (sp->deadline + *vws->tmo) - now;
if (tmo < min_t) {
timeout = &min_ts;
......@@ -257,15 +257,17 @@ vws_pass(void *priv, struct waited *sp)
/*--------------------------------------------------------------------*/
static void * __match_proto__(waiter_init_f)
vws_init(waiter_handle_f *func, int *pfd)
vws_init(waiter_handle_f *func, int *pfd, volatile double *tmo)
{
struct vws *vws;
AN(func);
AN(pfd);
AN(tmo);
ALLOC_OBJ(vws, VWS_MAGIC);
AN(vws);
vws->func = func;
vws->tmo = tmo;
VTAILQ_INIT(&vws->sesshead);
AZ(pthread_create(&vws->ports_thread, NULL, vws_thread, vws));
return (vws);
......
......@@ -38,7 +38,7 @@ enum wait_event {
};
typedef void waiter_handle_f(struct waited *, enum wait_event, double now);
typedef void* waiter_init_f(waiter_handle_f *, int *);
typedef void* waiter_init_f(waiter_handle_f *, int *, volatile double *);
typedef int waiter_pass_f(void *priv, struct waited *);
#define WAITER_DEFAULT "platform dependent"
......@@ -51,7 +51,7 @@ struct waiter_impl {
/* cache_waiter.c */
int WAIT_Enter(const struct waiter *, struct waited *);
struct waiter *WAIT_Init(waiter_handle_f *);
struct waiter *WAIT_Init(waiter_handle_f *, volatile double *timeout);
const char *WAIT_GetName(void);
/* mgt_waiter.c */
......
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