From: Willy Tarreau Date: Thu, 15 Apr 2021 17:48:44 +0000 (+0200) Subject: CLEANUP: pools: move the lock to the only __pool_get_first() that needs it X-Git-Tag: v2.4-dev17~72 X-Git-Url: http://git.haproxy.org/?a=commitdiff_plain;h=254321183019117f90360cc18a810c22a46dab01;p=haproxy-3.0.git CLEANUP: pools: move the lock to the only __pool_get_first() that needs it Now that __pool_alloc() only surrounds __pool_get_first() with the lock, let's move it to the only variant that requires it and remove the ugly ifdefs from the function. This is safe because nobody else calls this function. --- diff --git a/include/haproxy/pool.h b/include/haproxy/pool.h index 8766687..a5c3619 100644 --- a/include/haproxy/pool.h +++ b/include/haproxy/pool.h @@ -209,19 +209,25 @@ static inline void __pool_free(struct pool_head *pool, void *ptr) * Returns a pointer to type taken from the pool if * available, otherwise returns NULL. No malloc() is attempted, and poisonning * is never performed. The purpose is to get the fastest possible allocation. + * This version takes the pool's lock in order to do this. */ static inline void *__pool_get_first(struct pool_head *pool) { void *p; + HA_SPIN_LOCK(POOL_LOCK, &pool->lock); if ((p = pool->free_list) != NULL) { pool->free_list = *POOL_LINK(pool, p); pool->used++; + } + HA_SPIN_UNLOCK(POOL_LOCK, &pool->lock); + #ifdef DEBUG_MEMORY_POOLS + if (p) { /* keep track of where the element was allocated from */ *POOL_LINK(pool, p) = (void *)pool; -#endif } +#endif return p; } @@ -274,13 +280,7 @@ static inline void *__pool_alloc(struct pool_head *pool, unsigned int flags) goto ret; #endif -#if !defined(CONFIG_HAP_LOCKLESS_POOLS) && !defined(CONFIG_HAP_NO_GLOBAL_POOLS) - HA_SPIN_LOCK(POOL_LOCK, &pool->lock); -#endif p = __pool_get_first(pool); -#if !defined(CONFIG_HAP_LOCKLESS_POOLS) && !defined(CONFIG_HAP_NO_GLOBAL_POOLS) - HA_SPIN_UNLOCK(POOL_LOCK, &pool->lock); -#endif if (!p) p = pool_alloc_nocache(pool); ret: