From: phk Date: Wed, 2 Aug 2006 07:23:45 +0000 (+0000) Subject: Convert pipe to use poll(2) on the two filedescriptors it cares about X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=04b5fc7bd3b157d4263bb116293c4a8d95c9440a;p=varnish Convert pipe to use poll(2) on the two filedescriptors it cares about and eliminate the per-workerthread event engine entirely. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@596 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index d9bfb8fb..39011176 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -95,7 +95,6 @@ struct acct { struct worker { unsigned magic; #define WORKER_MAGIC 0x6391adcf - struct event_base *eb; struct objhead *nobjhead; struct object *nobj; diff --git a/varnish-cache/bin/varnishd/cache_pipe.c b/varnish-cache/bin/varnishd/cache_pipe.c index ba893e94..55def91b 100644 --- a/varnish-cache/bin/varnishd/cache_pipe.c +++ b/varnish-cache/bin/varnishd/cache_pipe.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -20,26 +21,22 @@ struct edir { }; static void -rdf(int fd, short event, void *arg) +rdf(struct pollfd *fds, int idx) { int i, j; - struct edir *ep; char buf[BUFSIZ]; - (void)event; - - ep = arg; - i = read(fd, buf, sizeof buf); + i = read(fds[idx].fd, buf, sizeof buf); if (i <= 0) { - shutdown(fd, SHUT_RD); - shutdown(ep->fd, SHUT_WR); - AZ(event_del(&ep->ev)); + shutdown(fds[idx].fd, SHUT_RD); + shutdown(fds[1-idx].fd, SHUT_WR); + fds[idx].events = 0; } else { - j = write(ep->fd, buf, i); + j = write(fds[1-idx].fd, buf, i); if (i != j) { - shutdown(fd, SHUT_WR); - shutdown(ep->fd, SHUT_RD); - AZ(event_del(&ep->ev)); + shutdown(fds[idx].fd, SHUT_WR); + shutdown(fds[1-idx].fd, SHUT_RD); + fds[1-idx].events = 0; } } } @@ -48,9 +45,10 @@ void PipeSession(struct sess *sp) { struct vbe_conn *vc; - struct edir e1, e2; char *b, *e; struct worker *w; + struct pollfd fds[2]; + int i; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC); @@ -75,15 +73,22 @@ PipeSession(struct sess *sp) return; } - e1.fd = vc->fd; - e2.fd = sp->fd; - event_set(&e1.ev, sp->fd, EV_READ | EV_PERSIST, rdf, &e1); - AZ(event_base_set(w->eb, &e1.ev)); - event_set(&e2.ev, vc->fd, EV_READ | EV_PERSIST, rdf, &e2); - AZ(event_base_set(w->eb, &e2.ev)); - AZ(event_add(&e1.ev, NULL)); - AZ(event_add(&e2.ev, NULL)); - (void)event_base_loop(w->eb, 0); + memset(fds, 0, sizeof fds); + fds[0].fd = vc->fd; + fds[0].events = POLLIN | POLLERR; + fds[1].fd = sp->fd; + fds[1].events = POLLIN | POLLERR; + + while (fds[0].events || fds[1].events) { + fds[0].revents = 0; + fds[1].revents = 0; + i = poll(fds, 2, INFTIM); + assert(i > 0); + if (fds[0].revents) + rdf(fds, 0); + if (fds[1].revents) + rdf(fds, 1); + } vca_close_session(sp, "pipe"); VBE_ClosedFd(vc); } diff --git a/varnish-cache/bin/varnishd/cache_pool.c b/varnish-cache/bin/varnishd/cache_pool.c index bfe59dae..7bf689f7 100644 --- a/varnish-cache/bin/varnishd/cache_pool.c +++ b/varnish-cache/bin/varnishd/cache_pool.c @@ -137,9 +137,6 @@ wrk_thread(void *priv) AZ(pthread_cond_init(&w->cv, NULL)); - w->eb = event_init(); - assert(w->eb != NULL); - AZ(pthread_mutex_lock(&wrk_mtx)); w->nbr = VSL_stats->n_wrk; if (priv == NULL) { @@ -170,7 +167,6 @@ wrk_thread(void *priv) TAILQ_REMOVE(&wrk_head, w, list); AZ(pthread_mutex_unlock(&wrk_mtx)); VSL(SLT_WorkThread, 0, "%u suicide", w->nbr); - event_base_free(w->eb); AZ(pthread_cond_destroy(&w->cv)); return (NULL); }