From fe79e159aa4c3605c808cf0e5ac5c8c3a3d6455e Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Mon, 8 Dec 2014 16:35:23 +0100 Subject: MINOR: memory: implement pool_fast_alloc2() This function returns a pointer to type taken from the pool if available, otherwise returns NULL. No malloc() is attempted, and poisonning is never performed. This is intended for buffers where we never want to poison memory (useless) and where we'd prefer the caller to take care of pool refilling instead. --- include/common/memory.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/common/memory.h b/include/common/memory.h index 259e4ff..a6f0b17 100644 --- a/include/common/memory.h +++ b/include/common/memory.h @@ -187,6 +187,21 @@ void *pool_destroy2(struct pool_head *pool); }) /* + * Returns a pointer to type taken from the pool + * if available, otherwise returns NULL. No malloc() is attempted, + * and poisonning is never performed. This is intended for buffers. + */ +#define pool_fast_alloc2(pool) \ +({ \ + void *__p; \ + if ((__p = (pool)->free_list) != NULL) { \ + (pool)->free_list = *(void **)(pool)->free_list;\ + (pool)->used++; \ + } \ + __p; \ +}) + +/* * Puts a memory area back to the corresponding pool. * Items are chained directly through a pointer that * is written in the beginning of the memory area, so -- 1.7.12.1