MEDIUM: peers: update ->commitupdate out of the lock using a CAS
authorWilly Tarreau <w@1wt.eu>
Fri, 28 Jul 2023 14:02:16 +0000 (14:02 +0000)
committerWilly Tarreau <w@1wt.eu>
Fri, 11 Aug 2023 17:03:35 +0000 (19:03 +0200)
commit4eddf26f58ee2602385b5e7d3b626cd9977bd480
tree2baf31d60e95187683d7dcbf1a5865c076c91ab0
parentcc10fce9c2d74aace9bc0123e24100634de45e69
MEDIUM: peers: update ->commitupdate out of the lock using a CAS

The ->commitupdate index doesn't need to be kept consistent with other
operations, it only needs to be correct and to reflect the last known
value. Right now it's updated under the stick-table lock, which is
expensive and maintains this lock longer than needed. Let's move it
outside of the lock, and update it using a CAS. This patch simply
replaces the assignment with a CAS and makes sure all reads are atomic.
On failed CAS we use a simple cpu_relax(), no need for more as there
should not be that much contention here (updates are not that fast).
src/peers.c