REORG: atomic: reimplement pl_cpu_relax() from atomic-ops.h
authorWilly Tarreau <w@1wt.eu>
Tue, 2 Mar 2021 06:08:34 +0000 (07:08 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 5 Mar 2021 17:20:50 +0000 (18:20 +0100)
commit48e9cfb63568d7134a7c52acec65dcb840cfc33c
tree6b103edb31dc5f64cf865f959d801a58634cd150
parent07451aceab1ea0863b06f57629b618961edbb3ab
REORG: atomic: reimplement pl_cpu_relax() from atomic-ops.h

There is some confusion here as we need to place some cpu_relax statements
in some loops where it's not easily possible to condition them on the use
of threads. That's what atomic.h already does. So let's take the various
pl_cpu_relax() implementations from there and place them in atomic.h under
the name __ha_cpu_relax() and let them adapt to the presence or absence of
threads and to the architecture (currently only x86 and aarch64 use a barrier
instruction), though it's very likely that arm would work well with a cache
flushing ISB instruction as well).

This time they were implemented as expressions returning 1 rather than
statements, in order to ease their placement as the loop condition or the
continuation expression inside "for" loops. We should probably do the same
with barriers and a few such other ones.

(cherry picked from commit 958ae26c3558f0a5cdcb7a92cc535f1cd1ac9a64)
[wt: will be used by later fixes]
Signed-off-by: Willy Tarreau <w@1wt.eu>
include/haproxy/atomic.h