mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-22 14:21:25 +02:00
MEDIUM: pools: change the static pool creation to pass a registration
Now we're creating statically allocated registrations instead of passing all the parameters and allocating them on the fly. Not only this is simpler to extend (we're limited in number of INITCALL args), but it also leaves all of these in the data segment where they are easier to find when debugging.
This commit is contained in:
parent
f51d58bd2e
commit
ff62aacb20
@ -30,19 +30,37 @@
|
|||||||
#include <haproxy/pool-t.h>
|
#include <haproxy/pool-t.h>
|
||||||
#include <haproxy/thread.h>
|
#include <haproxy/thread.h>
|
||||||
|
|
||||||
/* This registers a call to create_pool_callback(ptr, name, size) */
|
/* This creates a pool_reg registers a call to create_pool_callback(ptr) with it.
|
||||||
|
* Do not use this one, use REGISTER_POOL() instead.
|
||||||
|
*/
|
||||||
|
#define __REGISTER_POOL(_line, _ptr, _name, _size) \
|
||||||
|
static struct pool_registration __pool_reg_##_line = { \
|
||||||
|
.name = _name, \
|
||||||
|
.size = _size, \
|
||||||
|
.flags = MEM_F_STATREG, \
|
||||||
|
.align = 0, \
|
||||||
|
}; \
|
||||||
|
INITCALL3(STG_POOL, create_pool_callback, (_ptr), (_name), &__pool_reg_##_line);
|
||||||
|
|
||||||
|
/* intermediary level for line number resolution, do not use this one, use
|
||||||
|
* REGISTER_POOL() instead.
|
||||||
|
*/
|
||||||
|
#define _REGISTER_POOL(line, ptr, name, size) \
|
||||||
|
__REGISTER_POOL(line, ptr, name, size)
|
||||||
|
|
||||||
|
/* This registers a call to create_pool_callback(ptr) with these args */
|
||||||
#define REGISTER_POOL(ptr, name, size) \
|
#define REGISTER_POOL(ptr, name, size) \
|
||||||
INITCALL3(STG_POOL, create_pool_callback, (ptr), (name), (size))
|
_REGISTER_POOL(__LINE__, ptr, name, size)
|
||||||
|
|
||||||
/* This macro declares a pool head <ptr> and registers its creation */
|
/* This macro declares a pool head <ptr> and registers its creation */
|
||||||
#define DECLARE_POOL(ptr, name, size) \
|
#define DECLARE_POOL(ptr, name, size) \
|
||||||
struct pool_head *(ptr) __read_mostly = NULL; \
|
struct pool_head *(ptr) __read_mostly = NULL; \
|
||||||
REGISTER_POOL(&ptr, name, size)
|
_REGISTER_POOL(__LINE__, &ptr, name, size)
|
||||||
|
|
||||||
/* This macro declares a static pool head <ptr> and registers its creation */
|
/* This macro declares a static pool head <ptr> and registers its creation */
|
||||||
#define DECLARE_STATIC_POOL(ptr, name, size) \
|
#define DECLARE_STATIC_POOL(ptr, name, size) \
|
||||||
static struct pool_head *(ptr) __read_mostly; \
|
static struct pool_head *(ptr) __read_mostly; \
|
||||||
REGISTER_POOL(&ptr, name, size)
|
_REGISTER_POOL(__LINE__, &ptr, name, size)
|
||||||
|
|
||||||
/* 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
|
||||||
@ -125,7 +143,7 @@ void pool_flush(struct pool_head *pool);
|
|||||||
void pool_gc(struct pool_head *pool_ctx);
|
void pool_gc(struct pool_head *pool_ctx);
|
||||||
struct pool_head *create_pool(const char *name, unsigned int size, unsigned int flags);
|
struct pool_head *create_pool(const char *name, unsigned int size, unsigned int flags);
|
||||||
struct pool_head *create_pool_from_reg(const char *name, struct pool_registration *reg);
|
struct pool_head *create_pool_from_reg(const char *name, struct pool_registration *reg);
|
||||||
void create_pool_callback(struct pool_head **ptr, char *name, unsigned int size);
|
void create_pool_callback(struct pool_head **ptr, char *name, struct pool_registration *reg);
|
||||||
void *pool_destroy(struct pool_head *pool);
|
void *pool_destroy(struct pool_head *pool);
|
||||||
void pool_destroy_all(void);
|
void pool_destroy_all(void);
|
||||||
void *__pool_alloc(struct pool_head *pool, unsigned int flags);
|
void *__pool_alloc(struct pool_head *pool, unsigned int flags);
|
||||||
|
@ -1536,12 +1536,12 @@ static int cli_io_handler_dump_pools(struct appctx *appctx)
|
|||||||
* resulting pointer into <ptr>. If the allocation fails, it quits with after
|
* resulting pointer into <ptr>. If the allocation fails, it quits with after
|
||||||
* emitting an error message.
|
* emitting an error message.
|
||||||
*/
|
*/
|
||||||
void create_pool_callback(struct pool_head **ptr, char *name, unsigned int size)
|
void create_pool_callback(struct pool_head **ptr, char *name, struct pool_registration *reg)
|
||||||
{
|
{
|
||||||
*ptr = create_pool(name, size, MEM_F_SHARED);
|
*ptr = create_pool_from_reg(name, reg);
|
||||||
if (!*ptr) {
|
if (!*ptr) {
|
||||||
ha_alert("Failed to allocate pool '%s' of size %u : %s. Aborting.\n",
|
ha_alert("Failed to allocate pool '%s' of size %u : %s. Aborting.\n",
|
||||||
name, size, strerror(errno));
|
name, reg->size, strerror(errno));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user