BUG/MEDIUM: threads: Fix the max/min calculation because of name clashes
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 9 Apr 2018 06:45:43 +0000 (08:45 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 10 Apr 2018 09:07:56 +0000 (11:07 +0200)
commit48aa13f286dde83a88dd8459ee91ebee027c04a6
tree5ea30fcf80a647689da51ac9bddaadd668153e4c
parentf7b7c3e2f2d0bdf835a204cbccdff8005292ccaf
BUG/MEDIUM: threads: Fix the max/min calculation because of name clashes

With gcc < 4.7, when HAProxy is built with threads, the macros
HA_ATOMIC_CAS/XCHG/STORE relies on the legacy __sync builtins. These macros
are slightly complicated than the versions relying on the '_atomic'
builtins. Internally, some local variables are defined, prefixed with '__' to
avoid name clashes with the caller.

On the other hand, the macros HA_ATOMIC_UPDATE_MIN/MAX call HA_ATOMIC_CAS. Some
local variables are also definied in these macros, following the same naming
rule as below. The problem is that '__new' variable is used in
HA_ATOMIC_MIN/_MAX and in HA_ATOMIC_CAS. Obviously, the behaviour is undefined
because '__new' in HA_ATOMIC_CAS is left uninitialized. Unfortunatly gcc fails
to detect this error.

To fix the problem, all internal variables to macros are now suffixed with name
of the macros to avoid clashes (for instance, '__new_cas' in HA_ATOMIC_CAS).

This patch must be backported in 1.8.
include/common/hathreads.h