[master] faf9ba4 More refactoring: HSH_* functions take struct worker as first argument

Poul-Henning Kamp phk at FreeBSD.org
Tue Sep 16 12:28:57 CEST 2014


commit faf9ba4883647829ca43727000349ac756a91754
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Sep 16 10:28:29 2014 +0000

    More refactoring:  HSH_* functions take struct worker as first argument

diff --git a/bin/varnishd/cache/cache_ban.c b/bin/varnishd/cache/cache_ban.c
index a7fd546..9311b75 100644
--- a/bin/varnishd/cache/cache_ban.c
+++ b/bin/varnishd/cache/cache_ban.c
@@ -1100,7 +1100,7 @@ ban_lurker_test_ban(struct worker *wrk, struct vsl_log *vsl, struct ban *bt,
 			EXP_Rearm(oc, oc->exp.t_origin, 0, 0, 0); // XXX fake now
 			VSC_C_main->bans_lurker_obj_killed++;
 		}
-		(void)HSH_DerefObjCore(wrk->stats, &oc);
+		(void)HSH_DerefObjCore(wrk, &oc);
 	}
 }
 
diff --git a/bin/varnishd/cache/cache_busyobj.c b/bin/varnishd/cache/cache_busyobj.c
index 53f5abe..f381e08 100644
--- a/bin/varnishd/cache/cache_busyobj.c
+++ b/bin/varnishd/cache/cache_busyobj.c
@@ -197,7 +197,7 @@ VBO_DerefBusyObj(struct worker *wrk, struct busyobj **pbo)
 
 	if (bo->fetch_objcore != NULL) {
 		AN(wrk);
-		(void)HSH_DerefObjCore(wrk->stats, &bo->fetch_objcore);
+		(void)HSH_DerefObjCore(wrk, &bo->fetch_objcore);
 	}
 
 	VCL_Rel(&bo->vcl);
diff --git a/bin/varnishd/cache/cache_expire.c b/bin/varnishd/cache/cache_expire.c
index 6753669..3d8caa5 100644
--- a/bin/varnishd/cache/cache_expire.c
+++ b/bin/varnishd/cache/cache_expire.c
@@ -340,7 +340,7 @@ EXP_NukeOne(struct worker *wrk, struct lru *lru)
 	exp_mail_it(oc);
 
 	VSLb(wrk->vsl, SLT_ExpKill, "LRU x=%u", ObjGetXID(oc, wrk->stats));
-	(void)HSH_DerefObjCore(wrk->stats, &oc);
+	(void)HSH_DerefObjCore(wrk, &oc);
 	return (1);
 }
 
@@ -385,7 +385,7 @@ exp_inbox(struct exp_priv *ep, struct objcore *oc, double now)
 			binheap_delete(ep->heap, oc->timer_idx);
 		}
 		assert(oc->timer_idx == BINHEAP_NOIDX);
-		(void)HSH_DerefObjCore(ep->wrk->stats, &oc);
+		(void)HSH_DerefObjCore(ep->wrk, &oc);
 		return;
 	}
 
@@ -465,7 +465,7 @@ exp_expire(struct exp_priv *ep, double now)
 	VSLb(&ep->vsl, SLT_ExpKill, "EXP_Expired x=%u t=%.0f",
 	    ObjGetXID(oc, ep->wrk->stats),
 	    EXP_Ttl(NULL, &oc->exp) - now);
-	(void)HSH_DerefObjCore(ep->wrk->stats, &oc);
+	(void)HSH_DerefObjCore(ep->wrk, &oc);
 	return (0);
 }
 
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index e6bc239..4080a8e 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -610,7 +610,7 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
 	assert (bo->state == BOS_REQ_DONE);
 
 	if (bo->do_stream) {
-		HSH_Unbusy(wrk->stats, bo->fetch_objcore);
+		HSH_Unbusy(wrk, bo->fetch_objcore);
 		VBO_setstate(bo, BOS_STREAM);
 	}
 
@@ -637,7 +637,7 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
 		assert(bo->state == BOS_STREAM);
 	else {
 		assert(bo->state == BOS_REQ_DONE);
-		HSH_Unbusy(wrk->stats, bo->fetch_objcore);
+		HSH_Unbusy(wrk, bo->fetch_objcore);
 	}
 
 	/* Recycle the backend connection before setting BOS_FINISHED to
@@ -679,7 +679,7 @@ vbf_stp_condfetch(struct worker *wrk, struct busyobj *bo)
 	AZ(ObjCopyAttr(bo->vfc, bo->ims_oc, OA_GZIPBITS));
 
 	if (bo->do_stream) {
-		HSH_Unbusy(wrk->stats, bo->fetch_objcore);
+		HSH_Unbusy(wrk, bo->fetch_objcore);
 		VBO_setstate(bo, BOS_STREAM);
 	}
 
@@ -706,7 +706,7 @@ vbf_stp_condfetch(struct worker *wrk, struct busyobj *bo)
 		return (F_STP_FAIL);
 
 	if (!bo->do_stream)
-		HSH_Unbusy(wrk->stats, bo->fetch_objcore);
+		HSH_Unbusy(wrk, bo->fetch_objcore);
 
 	assert(al == ol);
 	assert(ObjGetLen(bo->fetch_objcore, bo->wrk->stats) == al);
@@ -799,7 +799,7 @@ vbf_stp_error(struct worker *wrk, struct busyobj *bo)
 	VSB_delete(bo->synth_body);
 	bo->synth_body = NULL;
 
-	HSH_Unbusy(wrk->stats, bo->fetch_objcore);
+	HSH_Unbusy(wrk, bo->fetch_objcore);
 	VBO_setstate(bo, BOS_FINISHED);
 	return (F_STP_DONE);
 }
@@ -894,7 +894,7 @@ vbf_fetch_thread(struct worker *wrk, void *priv)
 	AZ(bo->fetch_objcore->busyobj);
 
 	if (bo->ims_oc != NULL)
-		(void)HSH_DerefObjCore(wrk->stats, &bo->ims_oc);
+		(void)HSH_DerefObjCore(wrk, &bo->ims_oc);
 
 
 	wrk->vsl = NULL;
diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c
index b102928..f8c4149 100644
--- a/bin/varnishd/cache/cache_hash.c
+++ b/bin/varnishd/cache/cache_hash.c
@@ -177,13 +177,13 @@ HSH_Cleanup(struct worker *wrk)
 }
 
 void
-HSH_DeleteObjHead(struct dstat *ds, struct objhead *oh)
+HSH_DeleteObjHead(struct worker *wrk, struct objhead *oh)
 {
 
 	AZ(oh->refcnt);
 	assert(VTAILQ_EMPTY(&oh->objcs));
 	Lck_Delete(&oh->mtx);
-	ds->n_objecthead--;
+	wrk->stats->n_objecthead--;
 	FREE_OBJ(oh);
 }
 
@@ -437,7 +437,7 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp,
 			if (oh->hits < LONG_MAX)
 				oh->hits++;
 			Lck_Unlock(&oh->mtx);
-			assert(HSH_DerefObjHead(wrk->stats, &oh));
+			assert(HSH_DerefObjHead(wrk, &oh));
 			*ocp = oc;
 			return (HSH_HIT);
 		}
@@ -465,7 +465,7 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp,
 			oh->hits++;
 		Lck_Unlock(&oh->mtx);
 		if (retval == HSH_EXP)
-			assert(HSH_DerefObjHead(wrk->stats, &oh));
+			assert(HSH_DerefObjHead(wrk, &oh));
 		*ocp = exp_oc;
 		return (retval);
 	}
@@ -513,12 +513,13 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp,
  */
 
 static void
-hsh_rush(struct dstat *ds, struct objhead *oh)
+hsh_rush(struct worker *wrk, struct objhead *oh)
 {
 	unsigned u;
 	struct req *req;
 	struct waitinglist *wl;
 
+	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 	CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC);
 	Lck_AssertHeld(&oh->mtx);
 	wl = oh->waitinglist;
@@ -528,7 +529,7 @@ hsh_rush(struct dstat *ds, struct objhead *oh)
 		if (req == NULL)
 			break;
 		CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
-		ds->busy_wakeup++;
+		wrk->stats->busy_wakeup++;
 		AZ(req->wrk);
 		VTAILQ_REMOVE(&wl->list, req, w_list);
 		DSL(DBG_WAITINGLIST, req->vsl->wid, "off waiting list");
@@ -543,7 +544,7 @@ hsh_rush(struct dstat *ds, struct objhead *oh)
 	if (VTAILQ_EMPTY(&wl->list)) {
 		oh->waitinglist = NULL;
 		FREE_OBJ(wl);
-		ds->n_waitinglist--;
+		wrk->stats->n_waitinglist--;
 	}
 }
 
@@ -602,7 +603,7 @@ double keep)
 			oc = ocp[n];
 			CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
 			EXP_Rearm(oc, now, ttl, grace, keep);
-			(void)HSH_DerefObjCore(wrk->stats, &oc);
+			(void)HSH_DerefObjCore(wrk, &oc);
 		}
 	} while (more);
 	WS_Release(wrk->aws, 0);
@@ -658,10 +659,11 @@ HSH_Complete(struct objcore *oc)
  */
 
 void
-HSH_Unbusy(struct dstat *ds, struct objcore *oc)
+HSH_Unbusy(struct worker *wrk, struct objcore *oc)
 {
 	struct objhead *oh;
 
+	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
 	oh = oc->objhead;
 	CHECK_OBJ(oh, OBJHEAD_MAGIC);
@@ -685,7 +687,7 @@ HSH_Unbusy(struct dstat *ds, struct objcore *oc)
 	VTAILQ_INSERT_HEAD(&oh->objcs, oc, list);
 	oc->flags &= ~OC_F_BUSY;
 	if (oh->waitinglist != NULL)
-		hsh_rush(ds, oh);
+		hsh_rush(wrk, oh);
 	Lck_Unlock(&oh->mtx);
 }
 
@@ -737,17 +739,17 @@ HSH_RefBusy(const struct objcore *oc)
  */
 
 int
-HSH_DerefObjCore(struct dstat *ds, struct objcore **ocp)
+HSH_DerefObjCore(struct worker *wrk, struct objcore **ocp)
 {
 	struct objcore *oc;
 	struct objhead *oh;
 	unsigned r;
 
 	AN(ocp);
-	AN(ds);
 	oc = *ocp;
 	*ocp = NULL;
 
+	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
 	assert(oc->refcnt > 0);
 
@@ -760,7 +762,7 @@ HSH_DerefObjCore(struct dstat *ds, struct objcore **ocp)
 	if (!r)
 		VTAILQ_REMOVE(&oh->objcs, oc, list);
 	if (oh->waitinglist != NULL)
-		hsh_rush(ds, oh);
+		hsh_rush(wrk, oh);
 	Lck_Unlock(&oh->mtx);
 	if (r != 0)
 		return (r);
@@ -769,23 +771,23 @@ HSH_DerefObjCore(struct dstat *ds, struct objcore **ocp)
 	AZ(oc->ban);
 
 	if (oc->stobj->stevedore != NULL)
-		ObjFreeObj(oc, ds);
+		ObjFreeObj(oc, wrk->stats);
 	FREE_OBJ(oc);
 
-	ds->n_objectcore--;
+	wrk->stats->n_objectcore--;
 	/* Drop our ref on the objhead */
 	assert(oh->refcnt > 0);
-	(void)HSH_DerefObjHead(ds, &oh);
+	(void)HSH_DerefObjHead(wrk, &oh);
 	return (0);
 }
 
 int
-HSH_DerefObjHead(struct dstat *ds, struct objhead **poh)
+HSH_DerefObjHead(struct worker *wrk, struct objhead **poh)
 {
 	struct objhead *oh;
 	int r;
 
-	AN(ds);
+	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 	AN(poh);
 	oh = *poh;
 	*poh = NULL;
@@ -802,7 +804,7 @@ HSH_DerefObjHead(struct dstat *ds, struct objhead **poh)
 	assert(oh->refcnt > 0);
 	r = hash->deref(oh);
 	if (!r)
-		HSH_DeleteObjHead(ds, oh);
+		HSH_DeleteObjHead(wrk, oh);
 	return (r);
 }
 
diff --git a/bin/varnishd/cache/cache_http1_fsm.c b/bin/varnishd/cache/cache_http1_fsm.c
index 970ea24..0f68cd1 100644
--- a/bin/varnishd/cache/cache_http1_fsm.c
+++ b/bin/varnishd/cache/cache_http1_fsm.c
@@ -378,7 +378,7 @@ HTTP1_Session(struct worker *wrk, struct req *req)
 	 */
 	if (req->req_step == R_STP_LOOKUP && VTCP_check_hup(sp->fd)) {
 		AN(req->hash_objhead);
-		(void)HSH_DerefObjHead(wrk->stats, &req->hash_objhead);
+		(void)HSH_DerefObjHead(wrk, &req->hash_objhead);
 		AZ(req->hash_objhead);
 		SES_Close(sp, SC_REM_CLOSE);
 		sdr = http1_cleanup(sp, wrk, req);
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index f0c418d..3ea3452 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -140,7 +140,7 @@ cnt_deliver(struct worker *wrk, struct req *req)
 
 	if (wrk->handling != VCL_RET_DELIVER) {
 		assert(req->objcore == req->objcore);
-		(void)HSH_DerefObjCore(wrk->stats, &req->objcore);
+		(void)HSH_DerefObjCore(wrk, &req->objcore);
 		http_Teardown(req->resp);
 
 		switch (wrk->handling) {
@@ -192,7 +192,7 @@ cnt_deliver(struct worker *wrk, struct req *req)
 	}
 
 	assert(WRW_IsReleased(wrk));
-	(void)HSH_DerefObjCore(wrk->stats, &req->objcore);
+	(void)HSH_DerefObjCore(wrk, &req->objcore);
 	http_Teardown(req->resp);
 	return (REQ_FSM_DONE);
 }
@@ -301,7 +301,7 @@ cnt_fetch(struct worker *wrk, struct req *req)
 	if (req->objcore->flags & OC_F_FAILED) {
 		req->err_code = 503;
 		req->req_step = R_STP_SYNTH;
-		(void)HSH_DerefObjCore(wrk->stats, &req->objcore);
+		(void)HSH_DerefObjCore(wrk, &req->objcore);
 		AZ(req->objcore);
 		return (REQ_FSM_MORE);
 	}
@@ -401,7 +401,7 @@ cnt_lookup(struct worker *wrk, struct req *req)
 		VSLb(req->vsl, SLT_HitPass, "%u",
 		    ObjGetXID(req->objcore, wrk->stats));
 		AZ(boc);
-		(void)HSH_DerefObjCore(wrk->stats, &req->objcore);
+		(void)HSH_DerefObjCore(wrk, &req->objcore);
 		wrk->stats->cache_hitpass++;
 		req->req_step = R_STP_PASS;
 		return (REQ_FSM_MORE);
@@ -431,7 +431,7 @@ cnt_lookup(struct worker *wrk, struct req *req)
 			req->ims_oc = oc;
 			req->req_step = R_STP_MISS;
 		} else {
-			(void)HSH_DerefObjCore(wrk->stats, &req->objcore);
+			(void)HSH_DerefObjCore(wrk, &req->objcore);
 			/*
 			 * We don't have a busy object, so treat this
 			 * like a pass
@@ -457,10 +457,10 @@ cnt_lookup(struct worker *wrk, struct req *req)
 	}
 
 	/* Drop our object, we won't need it */
-	(void)HSH_DerefObjCore(wrk->stats, &req->objcore);
+	(void)HSH_DerefObjCore(wrk, &req->objcore);
 
 	if (boc != NULL) {
-		(void)HSH_DerefObjCore(wrk->stats, &boc);
+		(void)HSH_DerefObjCore(wrk, &boc);
 		VRY_Clear(req);
 	}
 
@@ -497,7 +497,7 @@ cnt_miss(struct worker *wrk, struct req *req)
 		VBF_Fetch(wrk, req, req->objcore, req->ims_oc, VBF_NORMAL);
 		req->req_step = R_STP_FETCH;
 		if (req->ims_oc != NULL)
-			(void)HSH_DerefObjCore(wrk->stats, &req->ims_oc);
+			(void)HSH_DerefObjCore(wrk, &req->ims_oc);
 		return (REQ_FSM_MORE);
 	case VCL_RET_SYNTH:
 		req->req_step = R_STP_SYNTH;
@@ -513,8 +513,8 @@ cnt_miss(struct worker *wrk, struct req *req)
 	}
 	VRY_Clear(req);
 	if (req->ims_oc != NULL)
-		(void)HSH_DerefObjCore(wrk->stats, &req->ims_oc);
-	AZ(HSH_DerefObjCore(wrk->stats, &req->objcore));
+		(void)HSH_DerefObjCore(wrk, &req->ims_oc);
+	AZ(HSH_DerefObjCore(wrk, &req->objcore));
 	return (REQ_FSM_MORE);
 }
 
@@ -828,7 +828,7 @@ cnt_purge(struct worker *wrk, struct req *req)
 
 	HSH_Purge(wrk, boc->objhead, 0, 0, 0);
 
-	AZ(HSH_DerefObjCore(wrk->stats, &boc));
+	AZ(HSH_DerefObjCore(wrk, &boc));
 
 	VCL_purge_method(req->vcl, wrk, req, NULL, req->http->ws);
 	switch (wrk->handling) {
diff --git a/bin/varnishd/hash/hash_critbit.c b/bin/varnishd/hash/hash_critbit.c
index 0f7b7ec..78d5576 100644
--- a/bin/varnishd/hash/hash_critbit.c
+++ b/bin/varnishd/hash/hash_critbit.c
@@ -363,7 +363,7 @@ hcb_cleaner(struct worker *wrk, void *priv)
 		}
 		VTAILQ_FOREACH_SAFE(oh, &dead_h, hoh_list, oh2) {
 			VTAILQ_REMOVE(&dead_h, oh, hoh_list);
-			HSH_DeleteObjHead(wrk->stats, oh);
+			HSH_DeleteObjHead(wrk, oh);
 		}
 		Lck_Lock(&hcb_mtx);
 		VSTAILQ_CONCAT(&dead_y, &cool_y);
diff --git a/bin/varnishd/hash/hash_slinger.h b/bin/varnishd/hash/hash_slinger.h
index 0b1fca0..db722da 100644
--- a/bin/varnishd/hash/hash_slinger.h
+++ b/bin/varnishd/hash/hash_slinger.h
@@ -111,11 +111,11 @@ struct objhead {
 };
 
 void HSH_Fail(struct objcore *);
-void HSH_Unbusy(struct dstat *, struct objcore *);
+void HSH_Unbusy(struct worker *, struct objcore *);
 void HSH_Complete(struct objcore *oc);
-void HSH_DeleteObjHead(struct dstat *, struct objhead *oh);
-int HSH_DerefObjHead(struct dstat *, struct objhead **poh);
-int HSH_DerefObjCore(struct dstat *, struct objcore **ocp);
+void HSH_DeleteObjHead(struct worker *, struct objhead *oh);
+int HSH_DerefObjHead(struct worker *, struct objhead **poh);
+int HSH_DerefObjCore(struct worker *, struct objcore **ocp);
 #endif /* VARNISH_CACHE_CHILD */
 
 extern const struct hash_slinger hsl_slinger;



More information about the varnish-commit mailing list