[master] baf8541 Don't needlessly return struct object
Poul-Henning Kamp
phk at FreeBSD.org
Mon Sep 15 14:32:05 CEST 2014
commit baf854187adf4eb7bbb4dbef08468723201ef43f
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Sep 15 12:31:52 2014 +0000
Don't needlessly return struct object
diff --git a/bin/varnishd/storage/stevedore.c b/bin/varnishd/storage/stevedore.c
index 9f42422..c1fb802 100644
--- a/bin/varnishd/storage/stevedore.c
+++ b/bin/varnishd/storage/stevedore.c
@@ -218,7 +218,7 @@ STV_MkObject(struct stevedore *stv, struct objcore *oc, void *ptr)
* implement persistent storage can rely on.
*/
-struct object *
+int
stv_default_allocobj(struct stevedore *stv, struct objcore *oc, unsigned ltot)
{
struct object *o;
@@ -227,16 +227,16 @@ stv_default_allocobj(struct stevedore *stv, struct objcore *oc, unsigned ltot)
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
st = stv->alloc(stv, ltot);
if (st == NULL)
- return (NULL);
+ return (0);
if (st->space < ltot) {
stv->free(st);
- return (NULL);
+ return (0);
}
o = STV_MkObject(stv, oc, st->ptr);
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
st->len = sizeof(*o);
o->objstore = st;
- return (o);
+ return (1);
}
/*-------------------------------------------------------------------
@@ -248,11 +248,10 @@ stv_default_allocobj(struct stevedore *stv, struct objcore *oc, unsigned ltot)
int
STV_NewObject(struct busyobj *bo, const char *hint, unsigned wsl)
{
- struct object *o;
struct objcore *oc;
struct stevedore *stv, *stv0;
unsigned ltot;
- int i;
+ int i, j;
CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
oc = bo->fetch_objcore;
@@ -260,36 +259,33 @@ STV_NewObject(struct busyobj *bo, const char *hint, unsigned wsl)
assert(wsl > 0);
wsl = PRNDUP(wsl);
- ltot = sizeof *o + wsl;
+ ltot = sizeof(struct object) + wsl;
stv = stv0 = stv_pick_stevedore(bo->vsl, &hint);
AN(stv->allocobj);
- o = stv->allocobj(stv, oc, ltot);
- if (o == NULL && hint == NULL) {
+ j = stv->allocobj(stv, oc, ltot);
+ if (j == 0 && hint == NULL) {
do {
stv = stv_pick_stevedore(bo->vsl, &hint);
AN(stv->allocobj);
- o = stv->allocobj(stv, oc, ltot);
- } while (o == NULL && stv != stv0);
+ j = stv->allocobj(stv, oc, ltot);
+ } while (j == 0 && stv != stv0);
}
- if (o == NULL) {
+ if (j == 0) {
/* no luck; try to free some space and keep trying */
- for (i = 0; o == NULL && i < cache_param->nuke_limit; i++) {
+ for (i = 0; j == 0 && i < cache_param->nuke_limit; i++) {
if (EXP_NukeOne(bo->vsl, bo->stats, stv->lru) == -1)
break;
- o = stv->allocobj(stv, oc, ltot);
+ j = stv->allocobj(stv, oc, ltot);
}
}
- if (o == NULL)
+ if (j == 0)
return (0);
bo->stats->n_object++;
VSLb(bo->vsl, SLT_Storage, "%s %s",
oc->stobj->stevedore->name, oc->stobj->stevedore->ident);
- CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
- CHECK_OBJ_NOTNULL(o->objstore, STORAGE_MAGIC);
- AN(stv->methods);
return (1);
}
diff --git a/bin/varnishd/storage/storage.h b/bin/varnishd/storage/storage.h
index 5108e47..56c72b8 100644
--- a/bin/varnishd/storage/storage.h
+++ b/bin/varnishd/storage/storage.h
@@ -61,7 +61,7 @@ typedef void storage_open_f(const struct stevedore *);
typedef struct storage *storage_alloc_f(struct stevedore *, size_t size);
typedef void storage_trim_f(struct storage *, size_t size, int move_ok);
typedef void storage_free_f(struct storage *);
-typedef struct object *storage_allocobj_f(struct stevedore *, struct objcore *,
+typedef int storage_allocobj_f(struct stevedore *, struct objcore *,
unsigned ltot);
typedef void storage_close_f(const struct stevedore *);
typedef void storage_signal_close_f(const struct stevedore *);
diff --git a/bin/varnishd/storage/storage_persistent.c b/bin/varnishd/storage/storage_persistent.c
index 037d23b..411fc9a 100644
--- a/bin/varnishd/storage/storage_persistent.c
+++ b/bin/varnishd/storage/storage_persistent.c
@@ -504,7 +504,7 @@ smp_allocx(struct stevedore *st, size_t min_size, size_t max_size,
* Allocate an object
*/
-static struct object *
+static int
smp_allocobj(struct stevedore *stv, struct objcore *oc, unsigned ltot)
{
struct object *o;
@@ -519,13 +519,13 @@ smp_allocobj(struct stevedore *stv, struct objcore *oc, unsigned ltot)
/* Don't entertain already dead objects */
if ((oc->exp.ttl + oc->exp.grace + oc->exp.keep) <= 0.)
- return (NULL);
+ return (0);
ltot = IRNUP(sc, ltot);
st = smp_allocx(stv, ltot, ltot, &so, &objidx, &sg);
if (st == NULL)
- return (NULL);
+ return (0);
assert(st->space >= ltot);
@@ -550,7 +550,7 @@ smp_allocobj(struct stevedore *stv, struct objcore *oc, unsigned ltot)
smp_init_oc(oc, sg, objidx);
Lck_Unlock(&sc->mtx);
- return (o);
+ return (1);
}
/*--------------------------------------------------------------------
More information about the varnish-commit
mailing list