MINOR: compiler: implement an ONLY_ONCE() macro
authorWilly Tarreau <w@1wt.eu>
Thu, 26 Aug 2021 13:46:51 +0000 (15:46 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 3 Sep 2021 14:27:57 +0000 (16:27 +0200)
commitc878fcf2ab5352b2311ca8846739937820352698
tree47406d0dcceed22ff1ad6b581ea3544f8d21b2d6
parent3df7633eff8034a12d757357035500faa541b657
MINOR: compiler: implement an ONLY_ONCE() macro

There are regularly places, especially in config analysis, where we
need to report certain things (warnings or errors) only once, but
where implementing a counter is sufficiently deterrent so that it's
not done.

Let's add a simple ONLY_ONCE() macro that implements a static variable
(char) which is atomically turned on, and returns true if it's set for
the first time. This uses fairly compact code, a single byte of BSS
and is thread-safe. There are probably a number of places in the config
parser where this could be used. It may also be used to implement a
WARN_ON() similar to BUG_ON() but which would only warn once.

(cherry picked from commit 906f7daed16a3b1c4058b77fed44b3c4265e645f)
Signed-off-by: Willy Tarreau <w@1wt.eu>
(cherry picked from commit 6902527b83ed426793b3e89936f27b78c5c21f37)
Signed-off-by: Willy Tarreau <w@1wt.eu>
include/haproxy/compiler.h