Commit ccec288d authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

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.
parent a84e7687
......@@ -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);
}
/*---------------------------------------------------------------------
......
......@@ -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
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment