]> err.no Git - varnish/commitdiff
Avoid home-rolled circular list in stevedore, use regular VTAILQ,
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sat, 19 Jul 2008 06:46:42 +0000 (06:46 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sat, 19 Jul 2008 06:46:42 +0000 (06:46 +0000)
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
varnish-cache/bin/varnishd/stevedore.h

index 5fbbee2904eef37d5cc1d6e46c2a189c0b6a2bf1..9e40714a12b499f1dd0b1eb42639b4c827065e9f 100644 (file)
 #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);
+       }
 }
index 58ff1062b024d23507a209e8a0d89c392de19a9b..06870b568c22d14e9bd95e0e012816b42c2dcff9 100644 (file)
@@ -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);