]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: debug: check the match count in __BUG_ON_ONCE() and not in complain()
authorWilly Tarreau <w@1wt.eu>
Mon, 10 Aug 2026 14:50:39 +0000 (16:50 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 13 Aug 2026 15:43:30 +0000 (17:43 +0200)
The fix in commit 7a78d6c600 ("BUG/MINOR: debug: only dump the trace once
in __BUG_ON_ONCE()") warned that it's not strictly atomic, but we could
do better and take this opportunity for cleaning the code: use a fetch-add
in __BUG_ON_ONCE() and pass NULL to complain(), which thus no longer has
any call place requiring it to check a counter. This only very slightly
inflates the code (~138B) since each BUG_ON_ONCE() now has to load 1,
xadd(), check the return value instead of leaving it to complain(), but
this is totally marginal compared to the benefits.

This can even be backported where the fix above is backported if needed.

include/haproxy/bug.h

index 34f043dd4bf3339f55e49189b33589cc9b01cc43..0353a7db6b8550f1682fc8793af828fa35a6dc65 100644 (file)
@@ -437,9 +437,9 @@ extern __attribute__((__weak__)) struct debug_count __stop_dbg_cnt  HA_SECTION_S
                        msg ="\n" pfx "condition \"" #cond "\" matched at " file ":" #line "" sfx "\n" __VA_ARGS__ "\n"; \
                else                                                    \
                        msg = "\n" pfx "condition \"" #cond "\" matched at " file ":" #line "" sfx "\n"; \
-               complain(&__match_count_##line, msg, crash);            \
-               if (_HA_ATOMIC_LOAD(&__match_count_##line) > 1)         \
+               if (_HA_ATOMIC_FETCH_ADD(&__match_count_##line, 1))     \
                        break;                                          \
+               complain(NULL, msg, crash);                             \
                if (crash & 1)                                          \
                        ABORT_NOW();                                    \
                else                                                    \