[master] b477c37 Introduce SES_Ref() and SES_Rel(), so we can start to decorate the code with them.

Poul-Henning Kamp phk at FreeBSD.org
Wed Apr 6 00:09:05 CEST 2016


commit b477c3778bd503e229d45fdac9a5bafec317256e
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Apr 5 21:04:34 2016 +0000

    Introduce SES_Ref() and SES_Rel(), so we can start to decorate
    the code with them.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index bb2a2b5..eef6d8b 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -634,6 +634,7 @@ struct sess {
 #define SESS_MAGIC		0x2c2f9c5a
 
 	uint16_t		sattr[SA_LAST];
+	int			refcnt;
 	int			fd;
 	uint32_t		vxid;
 
@@ -944,7 +945,8 @@ struct sess *SES_New(struct pool *);
 void SES_Close(struct sess *, enum sess_close reason);
 void SES_Wait(struct sess *, const struct transport *);
 void SES_Delete(struct sess *, enum sess_close reason, double now);
-void SES_NewPool(struct pool *, unsigned pool_no);
+void SES_Ref(struct sess *sp);
+void SES_Rel(struct sess *sp);
 int SES_Reschedule_Req(struct req *);
 void SES_SetTransport(struct worker *, struct sess *, struct req *,
     const struct transport *);
diff --git a/bin/varnishd/cache/cache_esi_deliver.c b/bin/varnishd/cache/cache_esi_deliver.c
index ecb01bc..876a0b6 100644
--- a/bin/varnishd/cache/cache_esi_deliver.c
+++ b/bin/varnishd/cache/cache_esi_deliver.c
@@ -89,6 +89,7 @@ ved_include(struct req *preq, const char *src, const char *host,
 		return;
 
 	req = Req_New(wrk, preq->sp);
+	SES_Ref(preq->sp);
 	req->req_body_status = REQ_BODY_NONE;
 	AZ(req->vsl->wid);
 	req->vsl->wid = VXID_Get(wrk, VSL_CLIENTMARKER);
@@ -182,6 +183,7 @@ ved_include(struct req *preq, const char *src, const char *host,
 	req->wrk = NULL;
 
 	THR_SetRequest(preq);
+	SES_Rel(req->sp);
 	Req_Release(req);
 }
 
diff --git a/bin/varnishd/cache/cache_priv.h b/bin/varnishd/cache/cache_priv.h
index 2676680..ff354a6 100644
--- a/bin/varnishd/cache/cache_priv.h
+++ b/bin/varnishd/cache/cache_priv.h
@@ -95,6 +95,9 @@ void Pool_Init(void);
 /* cache_proxy.c [VPX] */
 task_func_t VPX_Proto_Sess;
 
+/* cache_session.c */
+void SES_NewPool(struct pool *, unsigned pool_no);
+
 /* cache_shmlog.c */
 void VSM_Init(void);
 void VSL_Setup(struct vsl_log *vsl, void *ptr, size_t len);
diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c
index 4eaee4b..6088fae 100644
--- a/bin/varnishd/cache/cache_session.c
+++ b/bin/varnishd/cache/cache_session.c
@@ -325,6 +325,7 @@ SES_New(struct pool *pp)
 	sp = MPL_Get(pp->mpl_sess, &sz);
 	sp->magic = SESS_MAGIC;
 	sp->pool = pp;
+	sp->refcnt = 1;
 	memset(sp->sattr, 0xff, sizeof sp->sattr);
 
 	e = (char*)sp + sz;
@@ -534,6 +535,31 @@ SES_Delete(struct sess *sp, enum sess_close reason, double now)
 }
 
 /*--------------------------------------------------------------------
+ */
+
+void
+SES_Ref(struct sess *sp)
+{
+
+	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+	Lck_Lock(&sp->mtx);
+	assert(sp->refcnt > 0);
+	sp->refcnt++;
+	Lck_Unlock(&sp->mtx);
+}
+
+void
+SES_Rel(struct sess *sp)
+{
+
+	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+	Lck_Lock(&sp->mtx);
+	assert(sp->refcnt > 0);
+	sp->refcnt--;
+	Lck_Unlock(&sp->mtx);
+}
+
+/*--------------------------------------------------------------------
  * Create and delete pools
  */
 



More information about the varnish-commit mailing list