mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-24 23:31:40 +02:00
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.
This commit is contained in:
parent
62405a2155
commit
e430e77dfd
@ -23,6 +23,7 @@
|
|||||||
#define _COMMON_MEMORY_H
|
#define _COMMON_MEMORY_H
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include <common/config.h>
|
#include <common/config.h>
|
||||||
#include <common/mini-clist.h>
|
#include <common/mini-clist.h>
|
||||||
@ -99,19 +100,21 @@ void *pool_destroy2(struct pool_head *pool);
|
|||||||
* first case, <pool_type> is updated to point to the
|
* first case, <pool_type> is updated to point to the
|
||||||
* next element in the list.
|
* next element in the list.
|
||||||
*/
|
*/
|
||||||
#define pool_alloc2(pool) \
|
static inline void *pool_alloc2(struct pool_head *pool)
|
||||||
({ \
|
{
|
||||||
void *__p; \
|
void *p;
|
||||||
if ((__p = (pool)->free_list) == NULL) \
|
|
||||||
__p = pool_refill_alloc(pool); \
|
if ((p = pool->free_list) == NULL) {
|
||||||
else { \
|
p = pool_refill_alloc(pool);
|
||||||
(pool)->free_list = *(void **)(pool)->free_list;\
|
}
|
||||||
(pool)->used++; \
|
else {
|
||||||
if (unlikely(mem_poison_byte)) \
|
pool->free_list = *(void **)pool->free_list;
|
||||||
memset(__p, mem_poison_byte, (pool)->size); \
|
pool->used++;
|
||||||
} \
|
if (unlikely(mem_poison_byte))
|
||||||
__p; \
|
memset(p, mem_poison_byte, pool->size);
|
||||||
})
|
}
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Puts a memory area back to the corresponding pool.
|
* 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
|
* pointer. Just like with the libc's free(), nothing
|
||||||
* is done if <ptr> is NULL.
|
* is done if <ptr> is NULL.
|
||||||
*/
|
*/
|
||||||
#define pool_free2(pool, ptr) \
|
static inline void pool_free2(struct pool_head *pool, void *ptr)
|
||||||
({ \
|
{
|
||||||
if (likely((ptr) != NULL)) { \
|
if (likely(ptr != NULL)) {
|
||||||
*(void **)(ptr) = (void *)(pool)->free_list; \
|
*(void **)ptr= (void *)pool->free_list;
|
||||||
(pool)->free_list = (void *)(ptr); \
|
pool->free_list = (void *)ptr;
|
||||||
(pool)->used--; \
|
pool->used--;
|
||||||
} \
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif /* _COMMON_MEMORY_H */
|
#endif /* _COMMON_MEMORY_H */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user