[master] ccec288 Change calling convention of HSH_Lookup() so the return value is what major case we hit, and the returned obj/busyobj goes into pointer arguments.
Poul-Henning Kamp
phk at varnish-cache.org
Wed Apr 10 21:50:48 CEST 2013
commit ccec288d5b47f6b52ee229de5fa0ceef89d559dc
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Wed Apr 10 19:49:58 2013 +0000
Change calling convention of HSH_Lookup() so the return value
is what major case we hit, and the returned obj/busyobj goes into
pointer arguments.
diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c
index 833f9fd..cfc4599 100644
--- a/bin/varnishd/cache/cache_hash.c
+++ b/bin/varnishd/cache/cache_hash.c
@@ -327,8 +327,9 @@ hsh_insert_busyobj(struct worker *wrk, struct objhead *oh)
*
*/
-struct objcore *
-HSH_Lookup(struct req *req, int wait_for_busy, int always_insert)
+enum lookup_e
+HSH_Lookup(struct req *req, struct objcore **ocp, struct busyobj **bop,
+ int wait_for_busy, int always_insert)
{
struct worker *wrk;
struct objhead *oh;
@@ -338,6 +339,11 @@ HSH_Lookup(struct req *req, int wait_for_busy, int always_insert)
double exp_entered;
int busy_found;
+ AN(ocp);
+ *ocp = NULL;
+ AN(bop);
+ *bop = NULL;
+
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
wrk = req->wrk;
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
@@ -368,10 +374,10 @@ HSH_Lookup(struct req *req, int wait_for_busy, int always_insert)
if (always_insert) {
/* Insert new objcore in objecthead and release mutex */
- oc = hsh_insert_busyobj(wrk, oh);
+ *ocp = hsh_insert_busyobj(wrk, oh);
/* NB: no deref of objhead, new object inherits reference */
Lck_Unlock(&oh->mtx);
- return (oc);
+ return (HSH_MISS);
}
assert(oh->refcnt > 0);
@@ -448,7 +454,8 @@ HSH_Lookup(struct req *req, int wait_for_busy, int always_insert)
assert(HSH_DerefObjHead(&wrk->stats, &oh));
if (!cache_param->obj_readonly && o->hits < INT_MAX)
o->hits++;
- return (oc);
+ *ocp = oc;
+ return (HSH_HIT);
}
if (busy_found) {
@@ -480,14 +487,14 @@ HSH_Lookup(struct req *req, int wait_for_busy, int always_insert)
*/
req->hash_objhead = oh;
Lck_Unlock(&oh->mtx);
- return (NULL);
+ return (HSH_BUSY);
}
/* Insert (precreated) objcore in objecthead and release mutex */
- oc = hsh_insert_busyobj(wrk, oh);
+ *ocp = hsh_insert_busyobj(wrk, oh);
/* NB: no deref of objhead, new object inherits reference */
Lck_Unlock(&oh->mtx);
- return (oc);
+ return (HSH_MISS);
}
/*---------------------------------------------------------------------
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index d0fb0e1..6ce4f3f 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -740,6 +740,7 @@ cnt_lookup(struct worker *wrk, struct req *req)
struct object *o;
struct objhead *oh;
struct busyobj *bo;
+ enum lookup_e lr;
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
@@ -751,11 +752,11 @@ cnt_lookup(struct worker *wrk, struct req *req)
VRY_Prep(req);
AZ(req->objcore);
- oc = HSH_Lookup(req,
+ lr = HSH_Lookup(req, &oc, &bo,
req->esi_level == 0 ? 1 : 0,
req->hash_always_miss ? 1 : 0
);
- if (oc == NULL) {
+ if (lr == HSH_BUSY) {
/*
* We lost the session to a busy object, disembark the
* worker thread. We return to STP_LOOKUP when the busy
diff --git a/bin/varnishd/hash/hash_slinger.h b/bin/varnishd/hash/hash_slinger.h
index 1ff7cac..76a47a7 100644
--- a/bin/varnishd/hash/hash_slinger.h
+++ b/bin/varnishd/hash/hash_slinger.h
@@ -30,6 +30,8 @@
struct sess;
struct req;
+struct objcore;
+struct busyobj;
struct worker;
struct object;
@@ -51,9 +53,19 @@ struct hash_slinger {
hash_deref_f *deref;
};
+enum lookup_e {
+ HSH_MISS,
+ HSH_BUSY,
+ HSH_HIT,
+ HSH_EXP,
+ HSH_EXPBUSY
+};
+
/* cache_hash.c */
void HSH_Cleanup(struct worker *w);
-struct objcore *HSH_Lookup(struct req *, int wait_for_busy, int always_insert);
+enum lookup_e HSH_Lookup(struct req *, struct objcore **, struct busyobj **,
+ int wait_for_busy, int always_insert);
+// struct objcore *HSH_Lookup(struct req *, int wait_for_busy, int always_insert);
void HSH_Ref(struct objcore *o);
void HSH_Drop(struct worker *, struct object **);
void HSH_Init(const struct hash_slinger *slinger);
More information about the varnish-commit
mailing list