Commit ce6b9d85 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

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: http://www.varnish-cache.org/svn/trunk/varnish-cache@2953 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 749e0581
......@@ -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);
}
}
......@@ -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);
......
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