summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src/mem-pool.c
diff options
context:
space:
mode:
Diffstat (limited to 'libglusterfs/src/mem-pool.c')
-rw-r--r--libglusterfs/src/mem-pool.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/libglusterfs/src/mem-pool.c b/libglusterfs/src/mem-pool.c
index f1a2c98de..aec1d909d 100644
--- a/libglusterfs/src/mem-pool.c
+++ b/libglusterfs/src/mem-pool.c
@@ -337,6 +337,41 @@ mem_pool_new_fn (unsigned long sizeof_type,
return mem_pool;
}
+void*
+mem_get0 (struct mem_pool *mem_pool)
+{
+ struct list_head *list = NULL;
+ void *ptr = NULL;
+
+ if (!mem_pool) {
+ gf_log ("mem-pool", GF_LOG_ERROR, "invalid argument");
+ return NULL;
+ }
+
+ LOCK (&mem_pool->lock);
+ {
+ if (mem_pool->cold_count) {
+ list = mem_pool->list.next;
+ list_del (list);
+
+ mem_pool->hot_count++;
+ mem_pool->cold_count--;
+
+ ptr = list;
+ goto fwd_addr_out;
+ }
+ ptr = MALLOC (mem_pool->real_sizeof_type);
+ goto unlocked_out;
+ }
+fwd_addr_out:
+ ptr = mem_pool_chunkhead2ptr (ptr);
+unlocked_out:
+
+ memset(ptr, 0, mem_pool->real_sizeof_type);
+ UNLOCK (&mem_pool->lock);
+
+ return ptr;
+}
void *
mem_get (struct mem_pool *mem_pool)