diff --git a/include/haproxy/pool.h b/include/haproxy/pool.h index d3074084f..36105f19f 100644 --- a/include/haproxy/pool.h +++ b/include/haproxy/pool.h @@ -97,6 +97,7 @@ void create_pool_callback(struct pool_head **ptr, char *name, unsigned int size) void *pool_destroy(struct pool_head *pool); void pool_destroy_all(void); int mem_should_fail(const struct pool_head *pool); +void *__pool_alloc(struct pool_head *pool, unsigned int flags); void __pool_free(struct pool_head *pool, void *ptr); @@ -298,52 +299,17 @@ static inline void pool_put_to_cache(struct pool_head *pool, void *ptr) /****************** Common high-level code ******************/ -/* - * Returns a pointer to type taken from the pool or - * dynamically allocated. In the first case, is updated to point to - * the next element in the list. is a binary-OR of POOL_F_* flags. - * Prefer using pool_alloc() which does the right thing without flags. - */ -static inline void *__pool_alloc(struct pool_head *pool, unsigned int flags) -{ - void *p = NULL; - -#ifdef DEBUG_FAIL_ALLOC - if (!(flags & POOL_F_NO_FAIL) && mem_should_fail(pool)) - return NULL; -#endif - - if (!p) - p = pool_get_from_cache(pool); - if (!p) - p = pool_alloc_nocache(pool); - - if (p) { - if (flags & POOL_F_MUST_ZERO) - memset(p, 0, pool->size); - else if (!(flags & POOL_F_NO_POISON) && mem_poison_byte >= 0) - memset(p, mem_poison_byte, pool->size); - } - return p; -} - /* * Returns a pointer to type taken from the pool or * dynamically allocated. Memory poisonning is performed if enabled. */ -static inline void *pool_alloc(struct pool_head *pool) -{ - return __pool_alloc(pool, 0); -} +#define pool_alloc(pool) __pool_alloc((pool), 0) /* * Returns a pointer to type taken from the pool or * dynamically allocated. The area is zeroed. */ -static inline void *pool_zalloc(struct pool_head *pool) -{ - return __pool_alloc(pool, POOL_F_MUST_ZERO); -} +#define pool_zalloc(pool) __pool_alloc((pool), POOL_F_MUST_ZERO) /* * Puts a memory area back to the corresponding pool. Just like with the libc's diff --git a/src/pool.c b/src/pool.c index 21b48af4d..f569897c9 100644 --- a/src/pool.c +++ b/src/pool.c @@ -588,6 +588,35 @@ void pool_gc(struct pool_head *pool_ctx) #endif /* CONFIG_HAP_POOLS */ +/* + * Returns a pointer to type taken from the pool or + * dynamically allocated. In the first case, is updated to point to + * the next element in the list. is a binary-OR of POOL_F_* flags. + * Prefer using pool_alloc() which does the right thing without flags. + */ +void *__pool_alloc(struct pool_head *pool, unsigned int flags) +{ + void *p = NULL; + +#ifdef DEBUG_FAIL_ALLOC + if (unlikely(!(flags & POOL_F_NO_FAIL) && mem_should_fail(pool))) + return NULL; +#endif + + if (!p) + p = pool_get_from_cache(pool); + if (unlikely(!p)) + p = pool_alloc_nocache(pool); + + if (likely(p)) { + if (unlikely(flags & POOL_F_MUST_ZERO)) + memset(p, 0, pool->size); + else if (unlikely(!(flags & POOL_F_NO_POISON) && mem_poison_byte >= 0)) + memset(p, mem_poison_byte, pool->size); + } + return p; +} + /* * Puts a memory area back to the corresponding pool. be valid. Using * pool_free() is preferred.