r5554 - trunk/varnish-cache/bin/varnishd
phk at varnish-cache.org
phk at varnish-cache.org
Thu Nov 18 10:42:19 CET 2010
Author: phk
Date: 2010-11-18 10:42:18 +0100 (Thu, 18 Nov 2010)
New Revision: 5554
Modified:
trunk/varnish-cache/bin/varnishd/stevedore.c
Log:
Cleanup[1] the stevedore object creation code in preparation for
more extensive work to it.
[1] If I wanted to be buzzword compliant, I'd say "refactor" :-)
Modified: trunk/varnish-cache/bin/varnishd/stevedore.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/stevedore.c 2010-11-18 09:26:39 UTC (rev 5553)
+++ trunk/varnish-cache/bin/varnishd/stevedore.c 2010-11-18 09:42:18 UTC (rev 5554)
@@ -52,6 +52,8 @@
static const struct stevedore * volatile stv_next;
+static const struct stevedore *stv_transient;
+
/*********************************************************************
* NB! Dirty trick alert:
*
@@ -94,33 +96,8 @@
return (stv);
}
-
/*********************************************************************/
-static void
-STV_InitObj(const struct sess *sp, struct object *o, unsigned wsl,
- unsigned lhttp, unsigned nhttp)
-{
-
- memset(o, 0, sizeof *o);
- o->magic = OBJECT_MAGIC;
-
- assert(PAOK(wsl));
- assert(PAOK(lhttp));
-
- o->http = HTTP_create(o + 1, nhttp);
- WS_Init(o->ws_o, "obj", (char *)(o + 1) + lhttp, wsl);
- WS_Assert(o->ws_o);
-
- http_Setup(o->http, o->ws_o);
- o->http->magic = HTTP_MAGIC;
- o->grace = NAN;
- o->entered = NAN;
- VTAILQ_INIT(&o->store);
- sp->wrk->stats.n_object++;
-}
-/*********************************************************************/
-
static struct storage *
stv_alloc(const struct sess *sp, size_t size, struct objcore *oc)
{
@@ -168,37 +145,51 @@
/*********************************************************************/
struct object *
-STV_NewObject(const struct sess *sp, unsigned l, double ttl, unsigned nhttp)
+STV_NewObject(const struct sess *sp, unsigned wsl, double ttl, unsigned nhttp)
{
struct object *o;
struct storage *st;
- unsigned lh;
+ unsigned lhttp;
(void)ttl;
- assert(l > 0);
- l = PRNDUP(l);
+ assert(wsl > 0);
+ wsl = PRNDUP(wsl);
- lh = HTTP_estimate(nhttp);
- lh = PRNDUP(lh);
+ lhttp = HTTP_estimate(nhttp);
+ lhttp = PRNDUP(lhttp);
if (!sp->wrk->cacheable) {
- o = malloc(sizeof *o + l + lh);
+ o = malloc(sizeof *o + wsl + lhttp);
XXXAN(o);
- STV_InitObj(sp, o, l, lh, nhttp);
- return (o);
- }
- st = stv_alloc(sp, sizeof *o + l + lh, sp->objcore);
- XXXAN(st);
- xxxassert(st->space >= (sizeof *o + l + lh));
+ st = NULL;
+ } else {
+ st = stv_alloc(sp, sizeof *o + wsl + lhttp, sp->objcore);
+ XXXAN(st);
+ xxxassert(st->space >= (sizeof *o + wsl + lhttp));
- st->len = st->space;
+ st->len = st->space;
- o = (void *)st->ptr; /* XXX: align ? */
+ o = (void *)st->ptr; /* XXX: align ? */
- l = PRNDDN(st->space - (sizeof *o + lh));
+ wsl = PRNDDN(st->space - (sizeof *o + lhttp));
+ }
+ memset(o, 0, sizeof *o);
+ o->magic = OBJECT_MAGIC;
- STV_InitObj(sp, o, l, lh, nhttp);
+ assert(PAOK(wsl));
+ assert(PAOK(lhttp));
+
+ o->http = HTTP_create(o + 1, nhttp);
+ WS_Init(o->ws_o, "obj", (char *)(o + 1) + lhttp, wsl);
+ WS_Assert(o->ws_o);
+
+ http_Setup(o->http, o->ws_o);
+ o->http->magic = HTTP_MAGIC;
+ o->grace = NAN;
+ o->entered = NAN;
+ VTAILQ_INIT(&o->store);
+ sp->wrk->stats.n_object++;
o->objstore = st;
return (o);
}
@@ -332,9 +323,6 @@
bprintf(stv->ident, "%.*s", l, spec);
}
- if (!strcmp(stv->ident, TRANSIENT_NAME))
- stv->transient = 1;
-
VTAILQ_FOREACH(stv2, &stevedores, list) {
if (strcmp(stv2->ident, stv->ident))
continue;
@@ -349,10 +337,15 @@
else if (ac != 0)
ARGV_ERR("(-s%s) too many arguments\n", stv->name);
- VTAILQ_INSERT_TAIL(&stevedores, stv, list);
-
- if (!stv_next)
- stv_next = VTAILQ_FIRST(&stevedores);
+ if (!strcmp(stv->ident, TRANSIENT_NAME)) {
+ stv->transient = 1;
+ AZ(stv_transient);
+ stv_transient = stv;
+ } else {
+ VTAILQ_INSERT_TAIL(&stevedores, stv, list);
+ if (!stv_next)
+ stv_next = VTAILQ_FIRST(&stevedores);
+ }
}
/*--------------------------------------------------------------------*/
More information about the varnish-commit
mailing list