From: Willy Tarreau Date: Wed, 6 Aug 2025 14:33:27 +0000 (+0200) Subject: MINOR: pools: add macros to declare pools based on a struct type X-Git-Tag: v3.3-dev6~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f0d0922aa18cec60dcc267bf1b5423f7b94e5865;p=thirdparty%2Fhaproxy.git MINOR: pools: add macros to declare pools based on a struct type 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. --- diff --git a/include/haproxy/pool.h b/include/haproxy/pool.h index bc13098cf..fdfd89225 100644 --- a/include/haproxy/pool.h +++ b/include/haproxy/pool.h @@ -80,6 +80,22 @@ 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 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 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