[master] 1afc578 Add a function to cheaply add a reference to an already referenced tcp_pool

Poul-Henning Kamp phk at FreeBSD.org
Thu Oct 5 08:59:10 UTC 2017


commit 1afc578c407e74734749d2b2a303521481bcc41d
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Oct 5 08:57:48 2017 +0000

    Add a function to cheaply add a reference to an already referenced tcp_pool

diff --git a/bin/varnishd/cache/cache_backend_cfg.c b/bin/varnishd/cache/cache_backend_cfg.c
index ca828b9..15b650b 100644
--- a/bin/varnishd/cache/cache_backend_cfg.c
+++ b/bin/varnishd/cache/cache_backend_cfg.c
@@ -71,7 +71,6 @@ VRT_new_backend(VRT_CTX, const struct vrt_backend *vrt)
 	struct director *d;
 	struct vsb *vsb;
 	struct vcl *vcl;
-	struct tcp_pool *tp = NULL;
 	const struct vrt_backend_probe *vbp;
 	int retval;
 
@@ -117,16 +116,14 @@ VRT_new_backend(VRT_CTX, const struct vrt_backend *vrt)
 	VTAILQ_INSERT_TAIL(&backends, b, list);
 	VSC_C_main->n_backend++;
 	b->tcp_pool = VTP_Ref(vrt->ipv4_suckaddr, vrt->ipv6_suckaddr);
-	if (vbp != NULL) {
-		tp = VTP_Ref(vrt->ipv4_suckaddr, vrt->ipv6_suckaddr);
-		assert(b->tcp_pool == tp);
-	}
 	Lck_Unlock(&backends_mtx);
 
 	VBE_fill_director(b);
 
-	if (vbp != NULL)
-		VBP_Insert(b, vbp, tp);
+	if (vbp != NULL) {
+		VTP_AddRef(b->tcp_pool);
+		VBP_Insert(b, vbp, b->tcp_pool);
+	}
 
 	retval = VCL_AddBackend(ctx->vcl, b);
 
diff --git a/bin/varnishd/cache/cache_tcp_pool.c b/bin/varnishd/cache/cache_tcp_pool.c
index be19ecb..0fdc57b 100644
--- a/bin/varnishd/cache/cache_tcp_pool.c
+++ b/bin/varnishd/cache/cache_tcp_pool.c
@@ -169,6 +169,21 @@ VTP_Ref(const struct suckaddr *ip4, const struct suckaddr *ip6)
 }
 
 /*--------------------------------------------------------------------
+ * Add a reference to a tcp_pool
+ */
+
+void
+VTP_AddRef(struct tcp_pool *tp)
+{
+	CHECK_OBJ_NOTNULL(tp, TCP_POOL_MAGIC);
+
+	Lck_Lock(&pools_mtx);
+	assert(tp->refcnt > 0);
+	tp->refcnt++;
+	Lck_Unlock(&pools_mtx);
+}
+
+/*--------------------------------------------------------------------
  * Release TCP pool, destroy if last reference.
  */
 
diff --git a/bin/varnishd/cache/cache_tcp_pool.h b/bin/varnishd/cache/cache_tcp_pool.h
index 435b10d..8e83140 100644
--- a/bin/varnishd/cache/cache_tcp_pool.h
+++ b/bin/varnishd/cache/cache_tcp_pool.h
@@ -55,6 +55,7 @@ struct vtp {
 
 /* cache_tcp_pool.c */
 struct tcp_pool *VTP_Ref(const struct suckaddr *ip4, const struct suckaddr *ip6);
+void VTP_AddRef(struct tcp_pool *);
 void VTP_Rel(struct tcp_pool **tpp);
 int VTP_Open(const struct tcp_pool *tp, double tmo, const struct suckaddr **sa);
 void VTP_Recycle(const struct worker *, struct tcp_pool *, struct vtp **);


More information about the varnish-commit mailing list