From 46a5948ed2975a65ce1e4b578ec0b9e0a10402ab Mon Sep 17 00:00:00 2001 From: Aurelien DARRAGON Date: Wed, 3 Sep 2025 15:23:00 +0200 Subject: [PATCH] MINOR: compiler: add ALWAYS_PAD() macro same as THREAD_PAD() but doesn't depend on haproxy being compiled with thread support. It may be useful for memory (or files) that may be shared between multiple processed. --- include/haproxy/compiler.h | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/include/haproxy/compiler.h b/include/haproxy/compiler.h index 52aee39b9..b5b3b083e 100644 --- a/include/haproxy/compiler.h +++ b/include/haproxy/compiler.h @@ -488,20 +488,33 @@ #endif #endif +/* add padding of the specified size */ +#define _PAD(x,l) char __pad_##l[x] + /* add optional padding of the specified size between fields in a structure, * only when threads are enabled. This is used to avoid false sharing of cache * lines for dynamically allocated structures which cannot guarantee alignment. */ #ifndef THREAD_PAD # ifdef USE_THREAD -# define __THREAD_PAD(x,l) char __pad_##l[x] -# define _THREAD_PAD(x,l) __THREAD_PAD(x, l) +# define _THREAD_PAD(x,l) _PAD(x, l) # define THREAD_PAD(x) _THREAD_PAD(x, __LINE__) # else # define THREAD_PAD(x) # endif #endif +/* add mandatory padding of the specified size between fields in a structure, + * This is used to avoid false sharing of cache lines for dynamically allocated + * structures which cannot guarantee alignment, or to ensure that the size of + * the struct remains consistent on architectures with different aligment + * constraints + */ +#ifndef ALWAYS_PAD +# define _ALWAYS_PAD(x,l) _PAD(x, l) +# define ALWAYS_PAD(x) _ALWAYS_PAD(x, __LINE__) +#endif + /* The THREAD_LOCAL type attribute defines thread-local storage and is defined * to __thread when threads are enabled or empty when disabled. */