From: Willy Tarreau Date: Tue, 23 Dec 2014 13:13:16 +0000 (+0100) Subject: CLEANUP: memory: replace macros pool_alloc2/pool_free2 with functions X-Git-Tag: v1.6-dev1~231 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e430e77dfd151e5d9aa760d98033455b16abe53a;p=thirdparty%2Fhaproxy.git CLEANUP: memory: replace macros pool_alloc2/pool_free2 with functions Using inline functions here makes the code more readable and reduces its size by about 2 kB. --- diff --git a/include/common/memory.h b/include/common/memory.h index 80fa586cb6..330d7ff51a 100644 --- a/include/common/memory.h +++ b/include/common/memory.h @@ -23,6 +23,7 @@ #define _COMMON_MEMORY_H #include +#include #include #include @@ -99,19 +100,21 @@ void *pool_destroy2(struct pool_head *pool); * first case, is updated to point to the * next element in the list. */ -#define pool_alloc2(pool) \ -({ \ - void *__p; \ - if ((__p = (pool)->free_list) == NULL) \ - __p = pool_refill_alloc(pool); \ - else { \ - (pool)->free_list = *(void **)(pool)->free_list;\ - (pool)->used++; \ - if (unlikely(mem_poison_byte)) \ - memset(__p, mem_poison_byte, (pool)->size); \ - } \ - __p; \ -}) +static inline void *pool_alloc2(struct pool_head *pool) +{ + void *p; + + if ((p = pool->free_list) == NULL) { + p = pool_refill_alloc(pool); + } + else { + pool->free_list = *(void **)pool->free_list; + pool->used++; + if (unlikely(mem_poison_byte)) + memset(p, mem_poison_byte, pool->size); + } + return p; +} /* * Puts a memory area back to the corresponding pool. @@ -122,14 +125,14 @@ void *pool_destroy2(struct pool_head *pool); * pointer. Just like with the libc's free(), nothing * is done if is NULL. */ -#define pool_free2(pool, ptr) \ -({ \ - if (likely((ptr) != NULL)) { \ - *(void **)(ptr) = (void *)(pool)->free_list; \ - (pool)->free_list = (void *)(ptr); \ - (pool)->used--; \ - } \ -}) +static inline void pool_free2(struct pool_head *pool, void *ptr) +{ + if (likely(ptr != NULL)) { + *(void **)ptr= (void *)pool->free_list; + pool->free_list = (void *)ptr; + pool->used--; + } +} #endif /* _COMMON_MEMORY_H */