src/ucx/mempool.c

changeset 99
b9a6af0ae41a
parent 91
fac51f87def0
child 135
471e28cca288
--- a/src/ucx/mempool.c	Mon Apr 06 16:36:25 2015 +0200
+++ b/src/ucx/mempool.c	Fri Oct 16 19:23:49 2015 +0200
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright 2013 Olaf Wintermann. All rights reserved.
+ * Copyright 2015 Olaf Wintermann. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -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