diff --git a/include/common/memory.h b/include/common/memory.h index 84ec18e14..d3950ca5d 100644 --- a/include/common/memory.h +++ b/include/common/memory.h @@ -81,14 +81,15 @@ struct pool_free_list { }; #endif +/* Note below, in case of lockless pools, we still need the lock only for + * the flush() operation. + */ struct pool_head { void **free_list; #ifdef CONFIG_HAP_LOCKLESS_POOLS uintptr_t seq; - HA_SPINLOCK_T flush_lock; -#else - __decl_hathreads(HA_SPINLOCK_T lock); /* the spin lock */ #endif + __decl_hathreads(HA_SPINLOCK_T lock); /* the spin lock */ unsigned int used; /* how many chunks are currently in use */ unsigned int needed_avg;/* floating indicator between used and allocated */ unsigned int allocated; /* how many chunks have been allocated */ diff --git a/src/memory.c b/src/memory.c index 4552e4559..b442f0a10 100644 --- a/src/memory.c +++ b/src/memory.c @@ -139,11 +139,7 @@ struct pool_head *create_pool(char *name, unsigned int size, unsigned int flags) for (thr = 0; thr < MAX_THREADS; thr++) pool_cache[thr][idx].size = size; } -#ifndef CONFIG_HAP_LOCKLESS_POOLS HA_SPIN_INIT(&pool->lock); -#else - HA_SPIN_INIT(&pool->flush_lock); -#endif } pool->users++; return pool; @@ -227,7 +223,7 @@ void pool_flush(struct pool_head *pool) if (!pool) return; - HA_SPIN_LOCK(POOL_LOCK, &pool->flush_lock); + HA_SPIN_LOCK(POOL_LOCK, &pool->lock); do { cmp.free_list = pool->free_list; cmp.seq = pool->seq; @@ -235,7 +231,7 @@ void pool_flush(struct pool_head *pool) new.seq = cmp.seq + 1; } while (!_HA_ATOMIC_DWCAS(&pool->free_list, &cmp, &new)); __ha_barrier_atomic_store(); - HA_SPIN_UNLOCK(POOL_LOCK, &pool->flush_lock); + HA_SPIN_UNLOCK(POOL_LOCK, &pool->lock); next = cmp.free_list; while (next) { temp = next;