Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
I finally understood what this function is good for
authorMartin Quinson <martin.quinson@loria.fr>
Wed, 1 Feb 2012 15:30:15 +0000 (16:30 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Wed, 1 Feb 2012 15:30:15 +0000 (16:30 +0100)
include/xbt/mmalloc.h
src/xbt/mmalloc/detach.c
src/xbt/mmalloc/mm_legacy.c

index 1148c72..d3d23a7 100644 (file)
@@ -39,15 +39,13 @@ extern void *mvalloc(void *md, size_t size);
 
 extern void *mmalloc_attach(int fd, void *baseaddr);
 
-extern void mmalloc_pre_detach(void *md);
+extern void mmalloc_detach_no_free(void *md);
 
 extern void *mmalloc_detach(void *md);
 
 /* return the heap used when NULL is passed as first argument to any mm* function */
 extern void *mmalloc_get_default_md(void);
 
-extern int mmtrace(void);
-
 extern void *mmalloc_findbase(int size);
 
 extern int mmalloc_compare_heap(void *h1, void *h2, void *std_heap_addr);
index 5dfaf42..8df6e5e 100644 (file)
 #include <sys/types.h>
 #include "mmprivate.h"
 
+/* Terminate access to a mmalloc managed region, but do not free its content.
+ * This is for example useful for the base region where ldl stores its data
+ *   because it leaves the place after us.
+ */
+void mmalloc_detach_no_free(void *md)
+{
+  struct mdesc *mdp = md;
+
+  if(--mdp->refcount == 0){
+    LOCK(mdp) ;
+    sem_destroy(&mdp->sem);
+  }
+}
+
 /* Terminate access to a mmalloc managed region by unmapping all memory pages
    associated with the region, and closing the file descriptor if it is one
    that we opened.
    region we are about to unmap, so we first make a local copy of it on the
    stack and use the copy. */
 
-void mmalloc_pre_detach(void *md)
-{
-  struct mdesc *mdp = md;
-
-  if(--mdp->refcount == 0){
-    LOCK(mdp) ;
-    sem_destroy(&mdp->sem);
-  }
-}
-
 void *mmalloc_detach(void *md)
 {
   struct mdesc *mdp = (struct mdesc *)md;
@@ -51,7 +55,7 @@ void *mmalloc_detach(void *md)
 
     mdptemp->next_mdesc = mdp->next_mdesc;
 
-    mmalloc_pre_detach(md);
+    mmalloc_detach_no_free(md);
     mtemp = *(struct mdesc *) md;
 
     /* Now unmap all the pages associated with this region by asking for a
index 1415ad6..f676ae8 100644 (file)
@@ -172,7 +172,7 @@ void mmalloc_postexit(void)
 {
   /* Do not detach the default mdp or ldl won't be able to free the memory it allocated since we're in memory */
   //  mmalloc_detach(__mmalloc_default_mdp);
-  mmalloc_pre_detach(__mmalloc_default_mdp);
+  mmalloc_detach_no_free(__mmalloc_default_mdp);
 }
 
 int mmalloc_compare_heap(void *h1, void *h2, void *std_heap_addr){