Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Simplify the mmalloc library further
[simgrid.git] / src / xbt / mmalloc / mfree.c
index e9e7210..ff89699 100644 (file)
@@ -33,13 +33,6 @@ void __mmalloc_free(struct mdesc *mdp, void *ptr)
   type = mdp->heapinfo[block].busy.type;
   switch (type) {
   case 0:
-    /* Get as many statistics as early as we can.  */
-    mdp->heapstats.chunks_used--;
-    mdp->heapstats.bytes_used -=
-        mdp->heapinfo[block].busy.info.size * BLOCKSIZE;
-    mdp->heapstats.bytes_free +=
-        mdp->heapinfo[block].busy.info.size * BLOCKSIZE;
-
     /* Find the free cluster previous to this one in the free list.
        Start searching at the last block referenced; this may benefit
        programs with locality of allocation.  */
@@ -59,16 +52,15 @@ void __mmalloc_free(struct mdesc *mdp, void *ptr)
     /* Determine how to link this block into the free list.  */
     if (block == i + mdp->heapinfo[i].free.size) {
       /* Coalesce this block with its predecessor.  */
-      mdp->heapinfo[i].free.size += mdp->heapinfo[block].busy.info.size;
+      mdp->heapinfo[i].free.size += mdp->heapinfo[block].busy.info.block.size;
       block = i;
     } else {
       /* Really link this block back into the free list.  */
-      mdp->heapinfo[block].free.size = mdp->heapinfo[block].busy.info.size;
+      mdp->heapinfo[block].free.size = mdp->heapinfo[block].busy.info.block.size;
       mdp->heapinfo[block].free.next = mdp->heapinfo[i].free.next;
       mdp->heapinfo[block].free.prev = i;
       mdp->heapinfo[i].free.next = block;
       mdp->heapinfo[mdp->heapinfo[block].free.next].free.prev = block;
-      mdp->heapstats.chunks_free++;
     }
 
     /* Now that the block is linked in, see if we can coalesce it
@@ -81,7 +73,6 @@ void __mmalloc_free(struct mdesc *mdp, void *ptr)
       mdp->heapinfo[block].free.next
           = mdp->heapinfo[mdp->heapinfo[block].free.next].free.next;
       mdp->heapinfo[mdp->heapinfo[block].free.next].free.prev = block;
-      mdp->heapstats.chunks_free--;
     }
 
     /* Now see if we can return stuff to the system.  */
@@ -106,12 +97,6 @@ void __mmalloc_free(struct mdesc *mdp, void *ptr)
     break;
 
   default:
-    /* Do some of the statistics.  */
-    mdp->heapstats.chunks_used--;
-    mdp->heapstats.bytes_used -= 1 << type;
-    mdp->heapstats.chunks_free++;
-    mdp->heapstats.bytes_free += 1 << type;
-
     /* Get the address of the first free fragment in this block.  */
     prev = (struct list *)
         ((char *) ADDRESS(block) +
@@ -130,13 +115,8 @@ void __mmalloc_free(struct mdesc *mdp, void *ptr)
         next->prev = prev->prev;
       }
       mdp->heapinfo[block].busy.type = 0;
-      mdp->heapinfo[block].busy.info.size = 1;
-
-      /* Keep the statistics accurate.  */
-      mdp->heapstats.chunks_used++;
-      mdp->heapstats.bytes_used += BLOCKSIZE;
-      mdp->heapstats.chunks_free -= BLOCKSIZE >> type;
-      mdp->heapstats.bytes_free -= BLOCKSIZE;
+      mdp->heapinfo[block].busy.info.block.size = 1;
+      mdp->heapinfo[block].busy.info.block.busy_size = 0;
 
       mfree((void *) mdp, (void *) ADDRESS(block));
     } else if (mdp->heapinfo[block].busy.info.frag.nfree != 0) {
@@ -172,13 +152,11 @@ void __mmalloc_free(struct mdesc *mdp, void *ptr)
 
 /* Return memory to the heap.  */
 
-void mfree(void *md, void *ptr)
+void mfree(xbt_mheap_t mdp, void *ptr)
 {
-  struct mdesc *mdp;
   register struct alignlist *l;
 
   if (ptr != NULL) {
-    mdp = MD_TO_MDP(md);
     for (l = mdp->aligned_blocks; l != NULL; l = l->next) {
       if (l->aligned == ptr) {
         l->aligned = NULL;      /* Mark the slot in the list as free. */
@@ -186,10 +164,6 @@ void mfree(void *md, void *ptr)
         break;
       }
     }
-    if (mdp->mfree_hook != NULL) {
-      mdp->mfree_hook(mdp, ptr);
-    } else {
-      __mmalloc_free(mdp, ptr);
-    }
+    __mmalloc_free(mdp, ptr);
   }
 }