Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid
[simgrid.git] / src / xbt / mmalloc / mmalloc.c
index 5abbcd2..0af8597 100644 (file)
@@ -86,8 +86,9 @@ static void *morecore(struct mdesc *mdp, size_t size)
            mdp->heapsize * sizeof(malloc_info));
     oldinfo = mdp->heapinfo;
     newinfo[BLOCK(oldinfo)].busy.type = 0;
-    newinfo[BLOCK(oldinfo)].busy.info.size
+    newinfo[BLOCK(oldinfo)].busy.info.block.size
         = BLOCKIFY(mdp->heapsize * sizeof(malloc_info));
+    newinfo[BLOCK(oldinfo)].busy.info.block.busy_size = size;
     mdp->heapinfo = newinfo;
     __mmalloc_free(mdp, (void *) oldinfo);
     mdp->heapsize = newsize;
@@ -115,19 +116,14 @@ void *mmalloc(void *md, size_t size)
     size = 1;
 
   mdp = MD_TO_MDP(md);
-  LOCK(mdp);
 //  printf("(%s) Mallocing %d bytes on %p (default: %p)...",xbt_thread_self_name(),size,mdp,__mmalloc_default_mdp);fflush(stdout);
 
-
   if (mdp->mmalloc_hook != NULL) {
-    void *res = ((*mdp->mmalloc_hook) (md, size));
-    UNLOCK(mdp);
-    return res;
+    return mdp->mmalloc_hook(md, size);
   }
 
   if (!(mdp->flags & MMALLOC_INITIALIZED)) {
     if (!initialize(mdp)) {
-      UNLOCK(mdp);
       return (NULL);
     }
   }
@@ -172,13 +168,10 @@ void *mmalloc(void *md, size_t size)
     } else {
       /* No free fragments of the desired size, so get a new block
          and break it into fragments, returning the first.  */
-      UNLOCK(mdp);
       //printf("(%s) No free fragment...",xbt_thread_self_name());
       result = mmalloc(md, BLOCKSIZE);
       //printf("(%s) Fragment: %p...",xbt_thread_self_name(),result);
-      LOCK(mdp);
       if (result == NULL) {
-        UNLOCK(mdp);
         return (NULL);
       }
 
@@ -233,15 +226,14 @@ void *mmalloc(void *md, size_t size)
         }
         result = morecore(mdp, blocks * BLOCKSIZE);
         if (result == NULL) {
-          UNLOCK(mdp);
           return (NULL);
         }
         block = BLOCK(result);
         mdp->heapinfo[block].busy.type = 0;
-        mdp->heapinfo[block].busy.info.size = blocks;
+        mdp->heapinfo[block].busy.info.block.size = blocks;
+       mdp->heapinfo[block].busy.info.block.busy_size = size;
         mdp->heapstats.chunks_used++;
         mdp->heapstats.bytes_used += blocks * BLOCKSIZE;
-        UNLOCK(mdp);
         return (result);
       }
     }
@@ -272,12 +264,12 @@ void *mmalloc(void *md, size_t size)
     }
 
     mdp->heapinfo[block].busy.type = 0;
-    mdp->heapinfo[block].busy.info.size = blocks;
+    mdp->heapinfo[block].busy.info.block.size = blocks;
+    mdp->heapinfo[block].busy.info.block.busy_size = size;
     mdp->heapstats.chunks_used++;
     mdp->heapstats.bytes_used += blocks * BLOCKSIZE;
     mdp->heapstats.bytes_free -= blocks * BLOCKSIZE;
   }
   //printf("(%s) Done mallocing. Result is %p\n",xbt_thread_self_name(),result);fflush(stdout);
-  UNLOCK(mdp);
   return (result);
 }