]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: queue: reduce the locked area in pendconn_add()
authorWilly Tarreau <w@1wt.eu>
Wed, 21 Oct 2020 09:31:12 +0000 (11:31 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 22 Oct 2020 15:32:28 +0000 (17:32 +0200)
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

index dc3c23d2737647fd022d2d7de40e83785aa771b2..279dc2b7bb534cfd718ca2602fb4497953e4da1b 100644 (file)
@@ -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;
 }