]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: pools: permit to optionally specify extra size and alignment
authorWilly Tarreau <w@1wt.eu>
Mon, 11 Aug 2025 13:51:32 +0000 (15:51 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 11 Aug 2025 17:55:30 +0000 (19:55 +0200)
The common macros REGISTER_TYPED_POOL(), DECLARE_TYPED_POOL() and
DECLARE_STATIC_TYPED_POOL() will now take two optional arguments,
one being the extra size to be added to the structure, and a second
one being the desired alignment to enforce. This will permit to
specify alignments larger than the default ones promised to the
compiler.

include/haproxy/pool.h

index 5abe8c25b0c96eff975611c4ce4bc7029c62d6ed..3fd82390b79207537fffb7b5bd942a02dd48006f 100644 (file)
 
 /*** below are the typed pool macros, taking a type and an extra size ***/
 
-/* This registers a call to create_pool_callback(ptr) with these args */
-#define REGISTER_TYPED_POOL(ptr, name, type, extra)    \
-       _REGISTER_POOL(__LINE__, ptr, name, sizeof(type) + extra, __alignof__(type), __alignof__(type))
+/* This is only used by REGISTER_TYPED_POOL below */
+#define _REGISTER_TYPED_POOL(ptr, name, type, extra, align, ...)               \
+       _REGISTER_POOL(__LINE__, ptr, name, sizeof(type) + extra, __alignof__(type), align)
+
+/* This registers a call to create_pool_callback(ptr) with these args.
+ * It supports two optional args:
+ *  - extra: the extra size to be allocated at the end of the type. Def: 0.
+ *  - align: the desired alignment on the type. Def: 0 = same as type.
+ */
+#define REGISTER_TYPED_POOL(ptr, name, type, args...)  \
+       _REGISTER_TYPED_POOL(ptr, name, type, ##args, 0, 0)
 
 /* This macro declares an aligned pool head <ptr> and registers its creation */
-#define DECLARE_TYPED_POOL(ptr, name, type, extra)           \
+#define DECLARE_TYPED_POOL(ptr, name, type, args...)         \
        struct pool_head *(ptr) __read_mostly = NULL; \
-       _REGISTER_POOL(__LINE__, &ptr, name, sizeof(type) + extra, __alignof__(type), __alignof__(type))
+       _REGISTER_TYPED_POOL(&ptr, name, type, ##args, 0, 0)
 
 /* This macro declares a static aligned pool head <ptr> and registers its creation */
-#define DECLARE_STATIC_TYPED_POOL(ptr, name, type, extra)   \
+#define DECLARE_STATIC_TYPED_POOL(ptr, name, type, args...)   \
        static struct pool_head *(ptr) __read_mostly; \
-       _REGISTER_POOL(__LINE__, &ptr, name, sizeof(type) + extra, __alignof__(type), __alignof__(type))
+       _REGISTER_TYPED_POOL(&ptr, name, type, ##args, 0, 0)
 
 /* By default, free objects are linked by a pointer stored at the beginning of
  * the memory area. When DEBUG_MEMORY_POOLS is set, the allocated area is