mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-07 23:56:57 +02:00
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.
This commit is contained in:
parent
6ea0e3e2f8
commit
f0d0922aa1
@ -80,6 +80,22 @@
|
|||||||
static struct pool_head *(ptr) __read_mostly; \
|
static struct pool_head *(ptr) __read_mostly; \
|
||||||
_REGISTER_POOL(__LINE__, &ptr, name, size, align)
|
_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
|
/* 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
|
* 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
|
* inflated by the size of a pointer so that the link is placed at the end
|
||||||
|
Loading…
Reference in New Issue
Block a user