MEDIUM: pools: use a single pool_gc() function for locked and lockless

Locked and lockless shared pools don't need to use a different pool_gc()
function because this function isolates itself during the operation, so
we do not need to rely on DWCAS nor any atomic operation in fact. Let's
just get rid of the lockless one in favor of the simple one. This should
even result in a faster execution.

The ifdefs were slightly moved so that we can have pool_gc() defined
as soon as there are global pools, this avoids duplicating the function.

(cherry picked from commit 9b3ed51371693f70bab07e09cdd34e26e3a46d93)
Signed-off-by: Willy Tarreau <w@1wt.eu>
(cherry picked from commit a206cf93eb17e2d0f8184b91a0775ada763e7f71)
[wt: for 2.3, this was simplified, only the lockless version was
 reworked to work without the DWCAS, very similarly to the one in
 2.4 except that accounting still has to be done]
Signed-off-by: Willy Tarreau <w@1wt.eu>
(cherry picked from commit 294da644124403050eb1c4dd0aa1b7eb06372d9d)
Signed-off-by: Willy Tarreau <w@1wt.eu>
(cherry picked from commit 629c3683e2f774457ebedbff2c48c3e66331474b)
[wt: a number of previous optimizations such as 3e853ea74 ("MINOR:
     pools: release the pool's lock during the malloc/free calls"
     were not part of 2.0), hence some differences in the patch and
     its context, though the result is the same]
Signed-off-by: Willy Tarreau <w@1wt.eu>
diff --git a/src/memory.c b/src/memory.c
index 320b32a..9269271 100644
--- a/src/memory.c
+++ b/src/memory.c
@@ -263,21 +263,14 @@
 		thread_isolate();
 
 	list_for_each_entry(entry, &pools, list) {
-		while ((int)((volatile int)entry->allocated - (volatile int)entry->used) > (int)entry->minavail) {
-			struct pool_free_list cmp, new;
-
-			cmp.seq = entry->seq;
-			__ha_barrier_load();
-			cmp.free_list = entry->free_list;
-			__ha_barrier_load();
-			if (cmp.free_list == NULL)
-				break;
-			new.free_list = *POOL_LINK(entry, cmp.free_list);
-			new.seq = cmp.seq + 1;
-			if (HA_ATOMIC_DWCAS(&entry->free_list, &cmp, &new) == 0)
-				continue;
-			free(cmp.free_list);
-			_HA_ATOMIC_SUB(&entry->allocated, 1);
+		void *temp;
+		//qfprintf(stderr, "Flushing pool %s\n", entry->name);
+		while (entry->free_list &&
+		       (int)(entry->allocated - entry->used) > (int)entry->minavail) {
+			temp = entry->free_list;
+			entry->free_list = *POOL_LINK(entry, temp);
+			entry->allocated--;
+			free(temp);
 		}
 	}