Skip to content

Commit

Permalink
backend: Extract lock from vbe_connwait_dequeue
Browse files Browse the repository at this point in the history
  • Loading branch information
walid-git committed Jan 15, 2024
1 parent 974a136 commit d7ff4b3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
23 changes: 13 additions & 10 deletions bin/varnishd/cache/cache_backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,11 @@ vbe_connwait_signal_locked(struct backend *bp)
}

static void
vbe_connwait_dequeue(struct backend *bp, struct backend_cw *cw, int lock_it)
vbe_connwait_dequeue_locked(struct backend *bp, struct backend_cw *cw)
{
if (lock_it)
Lck_Lock(bp->director->mtx);
VTAILQ_REMOVE(&bp->cw_head, cw, cw_list);
vbe_connwait_signal_locked(bp);
if (lock_it)
Lck_Unlock(bp->director->mtx);
cw->cw_state = CW_DEQUEUED;
}

/*--------------------------------------------------------------------
Expand Down Expand Up @@ -224,8 +221,11 @@ vbe_dir_getfd(VRT_CTX, struct worker *wrk, VCL_BACKEND dir, struct backend *bp,
if (bo->htc == NULL) {
VSLb(bo->vsl, SLT_FetchError, "out of workspace");
/* XXX: counter ? */
if (cw->cw_state == CW_QUEUED)
vbe_connwait_dequeue(bp, cw, 1);
if (cw->cw_state == CW_QUEUED) {
Lck_Lock(bp->director->mtx);
vbe_connwait_dequeue_locked(bp, cw);
Lck_Unlock(bp->director->mtx);
}
PTOK(pthread_cond_destroy(&cw->cw_cond));
return (NULL);
}
Expand All @@ -243,8 +243,11 @@ vbe_dir_getfd(VRT_CTX, struct worker *wrk, VCL_BACKEND dir, struct backend *bp,
VRT_BACKEND_string(dir), err, VAS_errtxt(err));
VSC_C_main->backend_fail++;
bo->htc = NULL;
if (cw->cw_state == CW_QUEUED)
vbe_connwait_dequeue(bp, cw, 1);
if (cw->cw_state == CW_QUEUED) {
Lck_Lock(bp->director->mtx);
vbe_connwait_dequeue_locked(bp, cw);
Lck_Unlock(bp->director->mtx);
}
PTOK(pthread_cond_destroy(&cw->cw_cond));
return (NULL);
}
Expand All @@ -259,7 +262,7 @@ vbe_dir_getfd(VRT_CTX, struct worker *wrk, VCL_BACKEND dir, struct backend *bp,
bp->vsc->conn++;
bp->vsc->req++;
if (cw->cw_state == CW_QUEUED)
vbe_connwait_dequeue(bp, cw, 0);
vbe_connwait_dequeue_locked(bp, cw);

Lck_Unlock(bp->director->mtx);

Expand Down
1 change: 1 addition & 0 deletions bin/varnishd/cache/cache_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ struct conn_pool;
enum connwait_e {
CW_DO_CONNECT = 1,
CW_QUEUED,
CW_DEQUEUED,
CW_BE_BUSY,
};

Expand Down

0 comments on commit d7ff4b3

Please sign in to comment.