From 7fb8ce2144abe93be5479c8309bc7aa73c4f84ff Mon Sep 17 00:00:00 2001 From: Walid Boudebouda Date: Mon, 15 Jan 2024 19:07:17 +0100 Subject: [PATCH] backend: Add vbe_conwait_fini --- bin/varnishd/cache/cache_backend.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c index 4e302b416d..ae983889cf 100644 --- a/bin/varnishd/cache/cache_backend.c +++ b/bin/varnishd/cache/cache_backend.c @@ -158,6 +158,15 @@ vbe_connwait_dequeue_locked(struct backend *bp, struct connwait *cw) cw->cw_state = CW_DEQUEUED; } +static void +vbe_conwait_fini(struct connwait *cw) +{ + CHECK_OBJ_NOTNULL(cw, CONNWAIT_MAGIC); + assert(cw->cw_state != CW_QUEUED); + PTOK(pthread_cond_destroy(&cw->cw_cond)); + FINI_OBJ(cw); +} + /*-------------------------------------------------------------------- * Get a connection to the backend * @@ -227,7 +236,7 @@ vbe_dir_getfd(VRT_CTX, struct worker *wrk, VCL_BACKEND dir, struct backend *bp, "backend %s: busy", VRT_BACKEND_string(dir)); bp->vsc->busy++; VSC_C_main->backend_busy++; - PTOK(pthread_cond_destroy(&cw->cw_cond)); + vbe_conwait_fini(cw); return (NULL); } @@ -241,7 +250,7 @@ vbe_dir_getfd(VRT_CTX, struct worker *wrk, VCL_BACKEND dir, struct backend *bp, vbe_connwait_dequeue_locked(bp, cw); Lck_Unlock(bp->director->mtx); } - PTOK(pthread_cond_destroy(&cw->cw_cond)); + vbe_conwait_fini(cw); return (NULL); } bo->htc->doclose = SC_NULL; @@ -263,7 +272,7 @@ vbe_dir_getfd(VRT_CTX, struct worker *wrk, VCL_BACKEND dir, struct backend *bp, vbe_connwait_dequeue_locked(bp, cw); Lck_Unlock(bp->director->mtx); } - PTOK(pthread_cond_destroy(&cw->cw_cond)); + vbe_conwait_fini(cw); return (NULL); } @@ -301,7 +310,7 @@ vbe_dir_getfd(VRT_CTX, struct worker *wrk, VCL_BACKEND dir, struct backend *bp, bp->vsc->conn--; bp->vsc->req--; Lck_Unlock(bp->director->mtx); - PTOK(pthread_cond_destroy(&cw->cw_cond)); + vbe_conwait_fini(cw); return (NULL); } bo->acct.bereq_hdrbytes += err; @@ -320,7 +329,7 @@ vbe_dir_getfd(VRT_CTX, struct worker *wrk, VCL_BACKEND dir, struct backend *bp, bo->htc->first_byte_timeout, bo, bp); FIND_TMO(between_bytes_timeout, bo->htc->between_bytes_timeout, bo, bp); - PTOK(pthread_cond_destroy(&cw->cw_cond)); + vbe_conwait_fini(cw); return (pfd); }