]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: pools: add macros to declare pools based on a struct type
authorWilly Tarreau <w@1wt.eu>
Wed, 6 Aug 2025 14:33:27 +0000 (16:33 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 6 Aug 2025 17:20:36 +0000 (19:20 +0200)
DECLARE_TYPED_POOL() and friends take a name, a type and an extra
size (to be added to the size of the element), and will use this
to create the pool. This has the benefit of letting the compiler
automatically adapt sizeof() and alignof() based on the type
declaration.

include/haproxy/pool.h

index bc13098cf87ccc1f4fb19f2da4e898f19e1f045c..fdfd892254401a71cbedbace1053a1a65c61a160 100644 (file)
        static struct pool_head *(ptr) __read_mostly; \
        _REGISTER_POOL(__LINE__, &ptr, name, size, align)
 
+/*** 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))
+
+/* This macro declares an aligned pool head <ptr> and registers its creation */
+#define DECLARE_TYPED_POOL(ptr, name, type, extra)           \
+       struct pool_head *(ptr) __read_mostly = NULL; \
+       _REGISTER_POOL(__LINE__, &ptr, name, sizeof(type) + extra, __alignof__(type))
+
+/* This macro declares a static aligned pool head <ptr> and registers its creation */
+#define DECLARE_STATIC_TYPED_POOL(ptr, name, type, extra)   \
+       static struct pool_head *(ptr) __read_mostly; \
+       _REGISTER_POOL(__LINE__, &ptr, name, sizeof(type) + extra, __alignof__(type))
+
 /* 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
  * inflated by the size of a pointer so that the link is placed at the end