From d78311982007a2c778ff692c35c9d2787642c199 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Wed, 1 Feb 2012 16:30:15 +0100 Subject: [PATCH] I finally understood what this function is good for --- include/xbt/mmalloc.h | 4 +--- src/xbt/mmalloc/detach.c | 26 +++++++++++++++----------- src/xbt/mmalloc/mm_legacy.c | 2 +- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/include/xbt/mmalloc.h b/include/xbt/mmalloc.h index 1148c7272d..d3d23a7671 100644 --- a/include/xbt/mmalloc.h +++ b/include/xbt/mmalloc.h @@ -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); diff --git a/src/xbt/mmalloc/detach.c b/src/xbt/mmalloc/detach.c index 5dfaf4224d..8df6e5e827 100644 --- a/src/xbt/mmalloc/detach.c +++ b/src/xbt/mmalloc/detach.c @@ -14,6 +14,20 @@ #include #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. @@ -28,16 +42,6 @@ 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 diff --git a/src/xbt/mmalloc/mm_legacy.c b/src/xbt/mmalloc/mm_legacy.c index 1415ad6f64..f676ae816c 100644 --- a/src/xbt/mmalloc/mm_legacy.c +++ b/src/xbt/mmalloc/mm_legacy.c @@ -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){ -- 2.20.1