CLEANUP: atomic: add a fetch-and-xxx variant for common operations
authorWilly Tarreau <w@1wt.eu>
Tue, 6 Apr 2021 09:57:41 +0000 (11:57 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 7 Apr 2021 16:18:37 +0000 (18:18 +0200)
commit185157201c3cf1becc95a195b7e4bf2a1eb7ff58
treea10dc9146f9a5d2d4bb1e0696238911b43230e7a
parenta477150fd7ceba3af3d4db64bcf924f8a8f2da6c
CLEANUP: atomic: add a fetch-and-xxx variant for common operations

The fetch_and_xxx variant is often missing for add/sub/and/or. In fact
it was only provided for ADD under the name XADD which corresponds to
the x86 instruction name. But for destructive operations like AND and
OR it's missing even more as it's not possible to know the value before
modifying it.

This patch explicitly adds HA_ATOMIC_FETCH_{OR,AND,ADD,SUB} which
cover these standard operations, and renames XADD to FETCH_ADD (there
were only 6 call places).

In the future, backport of fixes involving such operations could simply
remap FETCH_ADD(x) to XADD(x), FETCH_SUB(x) to XADD(-x), and for the
OR/AND if needed, these could possibly be done using BTS/BTR.

It's worth noting that xchg could have been renamed to fetch_and_store()
but xchg already has well understood semantics and it wasn't needed to
go further.
include/haproxy/atomic.h
src/haproxy.c
src/log.c
src/proxy.c
src/stream.c