ucx/mempool.c

changeset 40
a95ee94b9204
parent 17
11dffb40cd91
child 70
88092b88ec00
--- a/ucx/mempool.c	Sat Sep 07 14:08:43 2013 +0200
+++ b/ucx/mempool.c	Mon Mar 17 18:42:01 2014 +0100
@@ -75,6 +75,20 @@
     
     pool->ndata = 0;
     pool->size = n;
+    
+    UcxAllocator *allocator = (UcxAllocator*)malloc(sizeof(UcxAllocator));
+    if(!allocator) {
+        free(pool->data);
+        free(pool);
+        return NULL;
+    }
+    allocator->malloc = (ucx_allocator_malloc)ucx_mempool_malloc;
+    allocator->calloc = (ucx_allocator_calloc)ucx_mempool_calloc;
+    allocator->realloc = (ucx_allocator_realloc)ucx_mempool_realloc;
+    allocator->free = (ucx_allocator_free)ucx_mempool_free;
+    allocator->pool = pool;
+    pool->allocator = allocator;
+    
     return pool;
 }
 
@@ -173,6 +187,7 @@
         }
     }
     free(pool->data);
+    free(pool->allocator);
     free(pool);
 }
 
@@ -189,16 +204,3 @@
     ucx_mempool_set_destr(rd, ucx_mempool_shared_destr);
 }
 
-UcxAllocator* ucx_mempool_allocator(UcxMempool *pool) {
-    UcxAllocator *allocator = (UcxAllocator*)ucx_mempool_malloc(
-            pool, sizeof(UcxAllocator));
-    if(!allocator) {
-        return NULL;
-    }
-    allocator->malloc = (ucx_allocator_malloc)ucx_mempool_malloc;
-    allocator->calloc = (ucx_allocator_calloc)ucx_mempool_calloc;
-    allocator->realloc = (ucx_allocator_realloc)ucx_mempool_realloc;
-    allocator->free = (ucx_allocator_free)ucx_mempool_free;
-    allocator->pool = pool;
-    return allocator;
-}

mercurial