[master] 84d08ecae Start reversing the layering of conn/tcp pool: free becomes a method.
Poul-Henning Kamp
phk at FreeBSD.org
Thu Jan 7 13:00:08 UTC 2021
commit 84d08ecae29d0a8702ec09bb85eb5869af66a807
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Thu Jan 7 11:58:36 2021 +0000
Start reversing the layering of conn/tcp pool: free becomes a method.
diff --git a/bin/varnishd/cache/cache_tcp_pool.c b/bin/varnishd/cache/cache_tcp_pool.c
index 31ddd9118..660c6f4d0 100644
--- a/bin/varnishd/cache/cache_tcp_pool.c
+++ b/bin/varnishd/cache/cache_tcp_pool.c
@@ -72,12 +72,14 @@ struct pfd {
typedef int cp_open_f(const struct conn_pool *, vtim_dur tmo, VCL_IP *ap);
typedef void cp_close_f(struct pfd *);
typedef void cp_name_f(const struct pfd *, char *, unsigned, char *, unsigned);
+typedef void cp_free_f(void *);
struct cp_methods {
cp_open_f *open;
cp_close_f *close;
cp_name_f *local_name;
cp_name_f *remote_name;
+ cp_free_f *free;
};
struct conn_pool {
@@ -105,16 +107,6 @@ struct conn_pool {
int holddown_errno;
};
-struct tcp_pool {
- unsigned magic;
-#define TCP_POOL_MAGIC 0x28b0e42a
-
- struct suckaddr *ip4;
- struct suckaddr *ip6;
- char *uds;
- struct conn_pool cp[1];
-};
-
static struct lock conn_pools_mtx;
static VTAILQ_HEAD(, conn_pool) conn_pools =
VTAILQ_HEAD_INITIALIZER(conn_pools);
@@ -268,7 +260,7 @@ VCP_AddRef(struct conn_pool *cp)
* Release Conn pool, destroy if last reference.
*/
-static int
+static void
VCP_Rel(struct conn_pool *cp)
{
struct pfd *pfd, *pfd2;
@@ -279,7 +271,7 @@ VCP_Rel(struct conn_pool *cp)
assert(cp->refcnt > 0);
if (--cp->refcnt > 0) {
Lck_Unlock(&conn_pools_mtx);
- return (1);
+ return;
}
AZ(cp->n_used);
VTAILQ_REMOVE(&conn_pools, cp, list);
@@ -304,7 +296,7 @@ VCP_Rel(struct conn_pool *cp)
Lck_Delete(&cp->mtx);
AZ(cp->n_conn);
AZ(cp->n_kill);
- return (0);
+ cp->methods->free(cp->priv);
}
/*--------------------------------------------------------------------
@@ -564,6 +556,28 @@ VCP_Wait(struct worker *wrk, struct pfd *pfd, vtim_real tmo)
/*--------------------------------------------------------------------
*/
+struct tcp_pool {
+ unsigned magic;
+#define TCP_POOL_MAGIC 0x28b0e42a
+
+ struct suckaddr *ip4;
+ struct suckaddr *ip6;
+ char *uds;
+ struct conn_pool cp[1];
+};
+
+static void v_matchproto_(cp_free_f)
+vtp_free(void *priv)
+{
+ struct tcp_pool *tp;
+
+ TAKE_OBJ_NOTNULL(tp, &priv, TCP_POOL_MAGIC);
+ free(tp->ip4);
+ free(tp->ip6);
+ free(tp->uds);
+ FREE_OBJ(tp);
+}
+
static inline int
tmo2msec(vtim_dur tmo)
{
@@ -627,6 +641,7 @@ static const struct cp_methods vtp_methods = {
.close = vtp_close,
.local_name = vtp_local_name,
.remote_name = vtp_remote_name,
+ .free = vtp_free,
};
/*--------------------------------------------------------------------
@@ -665,6 +680,7 @@ static const struct cp_methods vus_methods = {
.close = vtp_close,
.local_name = vus_name,
.remote_name = vus_name,
+ .free = vtp_free,
};
/*--------------------------------------------------------------------
@@ -751,13 +767,7 @@ VTP_Rel(struct tcp_pool **tpp)
struct tcp_pool *tp;
TAKE_OBJ_NOTNULL(tp, tpp, TCP_POOL_MAGIC);
- if (VCP_Rel(tp->cp))
- return;
-
- free(tp->ip4);
- free(tp->ip6);
- free(tp->uds);
- FREE_OBJ(tp);
+ VCP_Rel(tp->cp);
}
/*--------------------------------------------------------------------
More information about the varnish-commit
mailing list