[experimental-ims] 83753e2 Change the calling convention for waiters, to make it OO
Geoff Simmons
geoff at varnish-cache.org
Mon Jan 9 21:51:49 CET 2012
commit 83753e28342e4925e52ebf0b8e36ad9600c1e9a3
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Sat Sep 17 10:11:40 2011 +0000
Change the calling convention for waiters, to make it OO
diff --git a/bin/varnishd/cache_acceptor.c b/bin/varnishd/cache_acceptor.c
index 0692d46..2afc975 100644
--- a/bin/varnishd/cache_acceptor.c
+++ b/bin/varnishd/cache_acceptor.c
@@ -62,6 +62,8 @@ static struct waiter * const vca_waiters[] = {
static struct waiter const *vca_act;
+static void *waiter_priv;
+
pthread_t VCA_thread;
static struct timeval tv_sndtimeo;
static struct timeval tv_rcvtimeo;
@@ -384,10 +386,7 @@ vca_return_session(struct sess *sp)
*/
if (VTCP_nonblocking(sp->fd))
vca_close_session(sp, "remote closed");
- else if (vca_act->pass == NULL)
- assert(sizeof sp == write(vca_pipes[1], &sp, sizeof sp));
- else
- vca_act->pass(sp);
+ vca_act->pass(waiter_priv, sp);
}
/*--------------------------------------------------------------------*/
@@ -405,10 +404,11 @@ ccf_start(struct cli *cli, const char * const *av, void *priv)
AN(vca_act);
AN(vca_act->name);
+ AN(vca_act->init);
+ AN(vca_act->pass);
- if (vca_act->pass == NULL)
- AZ(pipe(vca_pipes));
- vca_act->init();
+ AZ(pipe(vca_pipes)); /* XXX */
+ waiter_priv = vca_act->init();
AZ(pthread_create(&VCA_thread, NULL, vca_acct, NULL));
VSL(SLT_Debug, 0, "Acceptor is %s", vca_act->name);
}
diff --git a/bin/varnishd/cache_waiter.h b/bin/varnishd/cache_waiter.h
index 2e0953b..9d6eee9 100644
--- a/bin/varnishd/cache_waiter.h
+++ b/bin/varnishd/cache_waiter.h
@@ -30,8 +30,8 @@
struct sess;
-typedef void waiter_init_f(void);
-typedef void waiter_pass_f(struct sess *);
+typedef void* waiter_init_f(void);
+typedef void waiter_pass_f(void *priv, struct sess *);
extern int vca_pipes[2];
diff --git a/bin/varnishd/cache_waiter_epoll.c b/bin/varnishd/cache_waiter_epoll.c
index fe64961..5726b03 100644
--- a/bin/varnishd/cache_waiter_epoll.c
+++ b/bin/varnishd/cache_waiter_epoll.c
@@ -222,6 +222,16 @@ vca_sess_timeout_ticker(void *arg)
/*--------------------------------------------------------------------*/
static void
+vca_epoll_pass(void *priv, hhstruct sess *sp)
+{
+
+ (void)priv;
+ assert(sizeof sp == write(vca_pipes[1], &sp, sizeof sp));
+}
+
+/*--------------------------------------------------------------------*/
+
+static void *
vca_epoll_init(void)
{
int i;
@@ -242,11 +252,15 @@ vca_epoll_init(void)
AZ(pthread_create(&vca_epoll_timeout_thread,
NULL, vca_sess_timeout_ticker, NULL));
AZ(pthread_create(&vca_epoll_thread, NULL, vca_main, NULL));
+ return(NULL);
}
+/*--------------------------------------------------------------------*/
+
struct waiter waiter_epoll = {
.name = "epoll",
.init = vca_epoll_init,
+ .pass = vca_epoll_pass,
};
#endif /* defined(HAVE_EPOLL_CTL) */
diff --git a/bin/varnishd/cache_waiter_kqueue.c b/bin/varnishd/cache_waiter_kqueue.c
index ea0e2fc..12e7bd4 100644
--- a/bin/varnishd/cache_waiter_kqueue.c
+++ b/bin/varnishd/cache_waiter_kqueue.c
@@ -204,6 +204,16 @@ vca_kqueue_main(void *arg)
/*--------------------------------------------------------------------*/
static void
+vca_kqueue_pass(void *priv, struct sess *sp)
+{
+
+ (void)priv;
+ assert(sizeof sp == write(vca_pipes[1], &sp, sizeof sp));
+}
+
+/*--------------------------------------------------------------------*/
+
+static void *
vca_kqueue_init(void)
{
int i;
@@ -215,11 +225,15 @@ vca_kqueue_init(void)
assert(i != -1);
AZ(pthread_create(&vca_kqueue_thread, NULL, vca_kqueue_main, NULL));
+ return (NULL);
}
+/*--------------------------------------------------------------------*/
+
struct waiter waiter_kqueue = {
.name = "kqueue",
.init = vca_kqueue_init,
+ .pass = vca_kqueue_pass,
};
#endif /* defined(HAVE_KQUEUE) */
diff --git a/bin/varnishd/cache_waiter_poll.c b/bin/varnishd/cache_waiter_poll.c
index 42b54dc..528a880 100644
--- a/bin/varnishd/cache_waiter_poll.c
+++ b/bin/varnishd/cache_waiter_poll.c
@@ -191,16 +191,29 @@ vca_main(void *arg)
}
/*--------------------------------------------------------------------*/
-
static void
+vca_poll_pass(void *priv, struct sess *sp)
+{
+
+ (void)priv;
+ assert(sizeof sp == write(vca_pipes[1], &sp, sizeof sp));
+}
+
+/*--------------------------------------------------------------------*/
+
+static void *
vca_poll_init(void)
{
vca_pollspace(256);
AZ(pthread_create(&vca_poll_thread, NULL, vca_main, NULL));
+ return (NULL);
}
+/*--------------------------------------------------------------------*/
+
struct waiter waiter_poll = {
.name = "poll",
.init = vca_poll_init,
+ .pass = vca_poll_pass,
};
diff --git a/bin/varnishd/cache_waiter_ports.c b/bin/varnishd/cache_waiter_ports.c
index 9ee3aea..f1cc55c 100644
--- a/bin/varnishd/cache_waiter_ports.c
+++ b/bin/varnishd/cache_waiter_ports.c
@@ -243,10 +243,14 @@ vca_main(void *arg)
}
}
+/*--------------------------------------------------------------------*/
+
static void
-vca_ports_pass(struct sess *sp)
+vca_ports_pass(void *priv, struct sess *sp)
{
int r;
+
+ (void)priv;
while((r = port_send(solaris_dport, 0, sp)) == -1 &&
errno == EAGAIN);
AZ(r);
@@ -254,13 +258,16 @@ vca_ports_pass(struct sess *sp)
/*--------------------------------------------------------------------*/
-static void
+static void *
vca_ports_init(void)
{
AZ(pthread_create(&vca_ports_thread, NULL, vca_main, NULL));
+ return (NULL);
}
+/*--------------------------------------------------------------------*/
+
struct waiter waiter_ports = {
.name = "ports",
.init = vca_ports_init,
More information about the varnish-commit
mailing list