]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: compiler: add ALWAYS_PAD() macro
authorAurelien DARRAGON <adarragon@haproxy.com>
Wed, 3 Sep 2025 13:23:00 +0000 (15:23 +0200)
committerAurelien DARRAGON <adarragon@haproxy.com>
Wed, 3 Sep 2025 14:28:46 +0000 (16:28 +0200)
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

index 52aee39b9f15fa3735d2c7c9582866dfd2c71cc7..b5b3b083e61e9ea7d180b8b47b377188f248f293 100644 (file)
 #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.
  */