MINOR: pools: extend pool_cache API to pass a pointer to a caller
This adds a caller to pool_put_to_cache() and pool_get_from_cache()
which will optionally be used to pass a pointer to their callers. For
now it's not used, only the API is extended to support this pointer.
diff --git a/include/haproxy/pool.h b/include/haproxy/pool.h
index e7b077a..a79eb28 100644
--- a/include/haproxy/pool.h
+++ b/include/haproxy/pool.h
@@ -112,7 +112,7 @@
void pool_evict_from_local_cache(struct pool_head *pool);
void pool_evict_from_local_caches(void);
-void pool_put_to_cache(struct pool_head *pool, void *ptr);
+void pool_put_to_cache(struct pool_head *pool, void *ptr, const void *caller);
#if defined(CONFIG_HAP_NO_GLOBAL_POOLS)
@@ -246,7 +246,7 @@
* <pool>. If none is available, tries to allocate from the shared cache, and
* returns NULL if nothing is available.
*/
-static inline void *pool_get_from_cache(struct pool_head *pool)
+static inline void *pool_get_from_cache(struct pool_head *pool, const void *caller)
{
struct pool_cache_item *item;
struct pool_cache_head *ph;
@@ -286,12 +286,12 @@
/* no cache pools implementation */
-static inline void *pool_get_from_cache(struct pool_head *pool)
+static inline void *pool_get_from_cache(struct pool_head *pool, const void *caller)
{
return NULL;
}
-static inline void pool_put_to_cache(struct pool_head *pool, void *ptr)
+static inline void pool_put_to_cache(struct pool_head *pool, void *ptr, const void *caller)
{
pool_free_nocache(pool, ptr);
}
diff --git a/src/pool.c b/src/pool.c
index f569897..4b12d7c 100644
--- a/src/pool.c
+++ b/src/pool.c
@@ -392,7 +392,7 @@
* While it is unspecified what the object becomes past this point, it is
* guaranteed to be released from the users' perpective.
*/
-void pool_put_to_cache(struct pool_head *pool, void *ptr)
+void pool_put_to_cache(struct pool_head *pool, void *ptr, const void *caller)
{
struct pool_cache_item *item = (struct pool_cache_item *)ptr;
struct pool_cache_head *ph = &pool->cache[tid];
@@ -597,6 +597,7 @@
void *__pool_alloc(struct pool_head *pool, unsigned int flags)
{
void *p = NULL;
+ void *caller = NULL;
#ifdef DEBUG_FAIL_ALLOC
if (unlikely(!(flags & POOL_F_NO_FAIL) && mem_should_fail(pool)))
@@ -604,7 +605,7 @@
#endif
if (!p)
- p = pool_get_from_cache(pool);
+ p = pool_get_from_cache(pool, caller);
if (unlikely(!p))
p = pool_alloc_nocache(pool);
@@ -623,13 +624,15 @@
*/
void __pool_free(struct pool_head *pool, void *ptr)
{
+ const void *caller = NULL;
+
/* we'll get late corruption if we refill to the wrong pool or double-free */
POOL_DEBUG_CHECK_MARK(pool, ptr);
if (unlikely(mem_poison_byte >= 0))
memset(ptr, mem_poison_byte, pool->size);
- pool_put_to_cache(pool, ptr);
+ pool_put_to_cache(pool, ptr, caller);
}