Mailing List Archive

r2953 - trunk/varnish-cache/bin/varnishd
Author: phk
Date: 2008-07-19 08:46:42 +0200 (Sat, 19 Jul 2008)
New Revision: 2953

Modified:
trunk/varnish-cache/bin/varnishd/stevedore.c
trunk/varnish-cache/bin/varnishd/stevedore.h
Log:
Avoid home-rolled circular list in stevedore, use regular VTAILQ,
the microoptimization does not justify the manual handling of ->prev
and ->next.



Modified: trunk/varnish-cache/bin/varnishd/stevedore.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/stevedore.c 2008-07-19 06:43:34 UTC (rev 2952)
+++ trunk/varnish-cache/bin/varnishd/stevedore.c 2008-07-19 06:46:42 UTC (rev 2953)
@@ -37,16 +37,14 @@
#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,9 +54,14 @@
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);
if (st != NULL)
@@ -134,15 +137,10 @@
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 @@
{
struct stevedore *stv;

- stv = stevedores;
- do {
+ VTAILQ_FOREACH(stv, &stevedores, list) {
if (stv->open != NULL)
stv->open(stv);
- stv = stv->next;
- } while (stv != stevedores);
+ }
}

Modified: trunk/varnish-cache/bin/varnishd/stevedore.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/stevedore.h 2008-07-19 06:43:34 UTC (rev 2952)
+++ trunk/varnish-cache/bin/varnishd/stevedore.h 2008-07-19 06:46:42 UTC (rev 2953)
@@ -52,7 +52,7 @@
/* private fields */
void *priv;

- struct stevedore *next, *prev;
+ VTAILQ_ENTRY(stevedore) list;
};

struct storage *STV_alloc(struct sess *sp, size_t size);