mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-21 22:01:31 +02:00
MINOR: pools: split pool_free() in the lockfree variant
This separates the validity tests from the code committing the object to the pool, in order to ease insertion of the thread-local cache.
This commit is contained in:
parent
0a93b6413f
commit
146794dc4f
@ -215,6 +215,21 @@ static inline void *pool_alloc(struct pool_head *pool)
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Locklessly add item <ptr> to pool <pool>, then update the pool used count.
|
||||||
|
* Both the pool and the pointer must be valid. Use pool_free() for normal
|
||||||
|
* operations.
|
||||||
|
*/
|
||||||
|
static inline void __pool_free(struct pool_head *pool, void *ptr)
|
||||||
|
{
|
||||||
|
void *free_list = pool->free_list;
|
||||||
|
|
||||||
|
do {
|
||||||
|
*POOL_LINK(pool, ptr) = (void *)free_list;
|
||||||
|
__ha_barrier_store();
|
||||||
|
} while (!HA_ATOMIC_CAS(&pool->free_list, (void *)&free_list, ptr));
|
||||||
|
HA_ATOMIC_SUB(&pool->used, 1);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Puts a memory area back to the corresponding pool.
|
* Puts a memory area back to the corresponding pool.
|
||||||
* Items are chained directly through a pointer that
|
* Items are chained directly through a pointer that
|
||||||
@ -227,19 +242,12 @@ static inline void *pool_alloc(struct pool_head *pool)
|
|||||||
static inline void pool_free(struct pool_head *pool, void *ptr)
|
static inline void pool_free(struct pool_head *pool, void *ptr)
|
||||||
{
|
{
|
||||||
if (likely(ptr != NULL)) {
|
if (likely(ptr != NULL)) {
|
||||||
void *free_list;
|
|
||||||
#ifdef DEBUG_MEMORY_POOLS
|
#ifdef DEBUG_MEMORY_POOLS
|
||||||
/* we'll get late corruption if we refill to the wrong pool or double-free */
|
/* we'll get late corruption if we refill to the wrong pool or double-free */
|
||||||
if (*POOL_LINK(pool, ptr) != (void *)pool)
|
if (*POOL_LINK(pool, ptr) != (void *)pool)
|
||||||
*(volatile int *)0 = 0;
|
*(volatile int *)0 = 0;
|
||||||
#endif
|
#endif
|
||||||
free_list = pool->free_list;
|
__pool_free(pool, ptr);
|
||||||
do {
|
|
||||||
*POOL_LINK(pool, ptr) = (void *)free_list;
|
|
||||||
__ha_barrier_store();
|
|
||||||
} while (!HA_ATOMIC_CAS(&pool->free_list, (void *)&free_list, ptr));
|
|
||||||
|
|
||||||
HA_ATOMIC_SUB(&pool->used, 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user