From c7eedf7a5a8992c911c6004fb3983afb45ef428d Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 21 Oct 2020 11:31:12 +0200 Subject: [PATCH] MINOR: queue: reduce the locked area in pendconn_add() Similarly to previous changes, we know if we're dealing with a server or proxy lock so let's directly lock at the finest possible places there. It's worth noting that a part of the operation consisting in an increment and update of a max could be done outside of the lock using atomic ops and a CAS. --- src/queue.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/queue.c b/src/queue.c index dc3c23d273..279dc2b7bb 100644 --- a/src/queue.c +++ b/src/queue.c @@ -383,26 +383,26 @@ struct pendconn *pendconn_add(struct stream *strm) p->strm = strm; p->strm_flags = strm->flags; - pendconn_queue_lock(p); - if (srv) { + HA_SPIN_LOCK(SERVER_LOCK, &p->srv->lock); srv->nbpend++; if (srv->nbpend > srv->counters.nbpend_max) srv->counters.nbpend_max = srv->nbpend; p->queue_idx = srv->queue_idx - 1; // for increment eb32_insert(&srv->pendconns, &p->node); + HA_SPIN_UNLOCK(SERVER_LOCK, &p->srv->lock); } else { + HA_RWLOCK_WRLOCK(PROXY_LOCK, &p->px->lock); px->nbpend++; if (px->nbpend > px->be_counters.nbpend_max) px->be_counters.nbpend_max = px->nbpend; p->queue_idx = px->queue_idx - 1; // for increment eb32_insert(&px->pendconns, &p->node); + HA_RWLOCK_WRUNLOCK(PROXY_LOCK, &p->px->lock); } strm->pend_pos = p; - pendconn_queue_unlock(p); - _HA_ATOMIC_ADD(&px->totpend, 1); return p; } -- 2.39.5