From: Willy Tarreau Date: Wed, 21 Oct 2020 09:31:12 +0000 (+0200) Subject: MINOR: queue: reduce the locked area in pendconn_add() X-Git-Tag: v2.3-dev8~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c7eedf7a5;p=thirdparty%2Fhaproxy.git 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. --- 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; }