From cf49e12f310e10cb2dc22476037869545f8f1138 Mon Sep 17 00:00:00 2001 From: phk Date: Sat, 19 Jul 2008 06:46:42 +0000 Subject: [PATCH] Avoid home-rolled circular list in stevedore, use regular VTAILQ, the microoptimization does not justify the manual handling of ->prev and ->next. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2953 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/stevedore.c | 38 ++++++++++++-------------- varnish-cache/bin/varnishd/stevedore.h | 2 +- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/varnish-cache/bin/varnishd/stevedore.c b/varnish-cache/bin/varnishd/stevedore.c index 5fbbee29..9e40714a 100644 --- a/varnish-cache/bin/varnishd/stevedore.c +++ b/varnish-cache/bin/varnishd/stevedore.c @@ -37,15 +37,13 @@ #include "cache.h" #include "stevedore.h" -/* - * Stevedores are kept in a circular list with the head pointer - * continuously moving from one element to the next. - */ - extern struct stevedore sma_stevedore; extern struct stevedore smf_stevedore; -static struct stevedore * volatile stevedores; +static VTAILQ_HEAD(, stevedore) stevedores = + VTAILQ_HEAD_INITIALIZER(stevedores); + +static struct stevedore * volatile stv_next; struct storage * STV_alloc(struct sess *sp, size_t size) @@ -56,8 +54,13 @@ STV_alloc(struct sess *sp, size_t size) for (;;) { /* pick a stevedore and bump the head along */ - /* XXX: only safe as long as pointer writes are atomic */ - stv = stevedores = stevedores->next; + stv = VTAILQ_NEXT(stv_next, list); + if (stv == NULL) + stv = VTAILQ_FIRST(&stevedores); + AN(stv); + + /* XXX: only safe as long as pointer writes are atomic */ + stv_next = stv; /* try to allocate from it */ st = stv->alloc(stv, size); @@ -134,15 +137,10 @@ STV_add(const char *spec) if (stv->init != NULL) stv->init(stv, q); - if (!stevedores) { - stevedores = stv->next = stv->prev = stv; - } else { - stv->next = stevedores; - stv->prev = stevedores->prev; - stv->next->prev = stv; - stv->prev->next = stv; - stevedores = stv; - } + VTAILQ_INSERT_TAIL(&stevedores, stv, list); + + if (!stv_next) + stv_next = VTAILQ_FIRST(&stevedores); } void @@ -150,10 +148,8 @@ STV_open(void) { struct stevedore *stv; - stv = stevedores; - do { + VTAILQ_FOREACH(stv, &stevedores, list) { if (stv->open != NULL) stv->open(stv); - stv = stv->next; - } while (stv != stevedores); + } } diff --git a/varnish-cache/bin/varnishd/stevedore.h b/varnish-cache/bin/varnishd/stevedore.h index 58ff1062..06870b56 100644 --- a/varnish-cache/bin/varnishd/stevedore.h +++ b/varnish-cache/bin/varnishd/stevedore.h @@ -52,7 +52,7 @@ struct stevedore { /* private fields */ void *priv; - struct stevedore *next, *prev; + VTAILQ_ENTRY(stevedore) list; }; struct storage *STV_alloc(struct sess *sp, size_t size); -- 2.39.5