Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
rename sup-mmap.c into mmorecore.c and simplify the code since we want no more than...
authorMartin Quinson <martin.quinson@loria.fr>
Wed, 1 Feb 2012 14:56:58 +0000 (15:56 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Wed, 1 Feb 2012 14:56:58 +0000 (15:56 +0100)
src/xbt/mmalloc/attach.c
src/xbt/mmalloc/detach.c
src/xbt/mmalloc/mm.c
src/xbt/mmalloc/mmalloc.c
src/xbt/mmalloc/mmorecore.c [moved from src/xbt/mmalloc/mmap-sup.c with 99% similarity]
src/xbt/mmalloc/mmprivate.h

index 5c6b3d2..228141f 100644 (file)
@@ -105,7 +105,6 @@ void *mmalloc_attach(int fd, void *baseaddr)
   strncpy(mdp->magic, MMALLOC_MAGIC, MMALLOC_MAGIC_SIZE);
   mdp->headersize = sizeof(mtemp);
   mdp->version = MMALLOC_VERSION;
-  mdp->morecore = __mmalloc_mmap_morecore;
   mdp->fd = fd;
   mdp->base = mdp->breakval = mdp->top = baseaddr;
   mdp->next_mdesc = NULL;
@@ -129,7 +128,7 @@ void *mmalloc_attach(int fd, void *baseaddr)
      fails, then close the file descriptor if it was opened by us, and arrange
      to return a NULL. */
 
-  if ((mbase = mdp->morecore(mdp, sizeof(mtemp))) != NULL) {
+  if ((mbase = mmorecore(mdp, sizeof(mtemp))) != NULL) {
     memcpy(mbase, mdp, sizeof(mtemp));
   } else {
     THROWF(system_error,0,"morecore failed to get some memory!");
@@ -192,7 +191,6 @@ static struct mdesc *reuse(int fd)
   if (__mmalloc_remap_core(&mtemp) == mtemp.base) {
     mdp = (struct mdesc *) mtemp.base;
     mdp->fd = fd;
-    mdp->morecore = __mmalloc_mmap_morecore;
     if(!mdp->refcount){
       sem_init(&mdp->sem, 1, 1);
       mdp->refcount++;
index e1157ed..5dfaf42 100644 (file)
@@ -57,7 +57,7 @@ void *mmalloc_detach(void *md)
     /* Now unmap all the pages associated with this region by asking for a
        negative increment equal to the current size of the region. */
 
-    if ((mtemp.morecore(&mtemp,
+    if ((mmorecore(&mtemp,
                         (char *) mtemp.base - (char *) mtemp.breakval)) ==
         NULL) {
       /* Deallocating failed.  Update the original malloc descriptor
index 7396add..ee44855 100644 (file)
@@ -22,7 +22,7 @@
 #include "mmstats.c"
 #include "mrealloc.c"
 #include "mvalloc.c"
-#include "mmap-sup.c"
+#include "mmorecore.c"
 #include "attach.c"
 #include "detach.c"
 #include "mm_legacy.c"
index fe893b0..e9e8588 100644 (file)
@@ -27,11 +27,11 @@ static void *align(struct mdesc *mdp, size_t size)
   void *result;
   unsigned long int adj;
 
-  result = mdp->morecore(mdp, size);
+  result = mmorecore(mdp, size);
   adj = RESIDUAL(result, BLOCKSIZE);
   if (adj != 0) {
     adj = BLOCKSIZE - adj;
-    mdp->morecore(mdp, adj);
+    mmorecore(mdp, adj);
     result = (char *) result + adj;
   }
   return (result);
@@ -78,7 +78,7 @@ static void *morecore(struct mdesc *mdp, size_t size)
     }
     newinfo = (malloc_info *) align(mdp, newsize * sizeof(malloc_info));
     if (newinfo == NULL) {
-      mdp->morecore(mdp, -size);
+      mmorecore(mdp, -size);
       return (NULL);
     }
     memset((void *) newinfo, 0, newsize * sizeof(malloc_info));
@@ -209,7 +209,7 @@ void *mmalloc(void *md, size_t size)
         lastblocks = mdp->heapinfo[block].free.size;
         if (mdp->heaplimit != 0 &&
             block + lastblocks == mdp->heaplimit &&
-            mdp->morecore(mdp, 0) == ADDRESS(block + lastblocks) &&
+            mmorecore(mdp, 0) == ADDRESS(block + lastblocks) &&
             (morecore(mdp, (blocks - lastblocks) * BLOCKSIZE)) != NULL) {
           /* Which block we are extending (the `final free
              block' referred to above) might have changed, if
similarity index 99%
rename from src/xbt/mmalloc/mmap-sup.c
rename to src/xbt/mmalloc/mmorecore.c
index 964e484..2c68d50 100644 (file)
@@ -53,7 +53,7 @@ static size_t pagesize;
     amount to either add to or subtract from the existing region.  Works
     like sbrk(), but using mmap(). */
 
-void *__mmalloc_mmap_morecore(struct mdesc *mdp, int size)
+void *mmorecore(struct mdesc *mdp, int size)
 {
   ssize_t test = 0;
   void *result = NULL;
index f351b59..3767365 100644 (file)
@@ -165,17 +165,6 @@ struct mdesc {
      preserved for future examination. */
   int saved_errno;
 
-  /* Pointer to the function that is used to get more core, or return core
-     to the system, for requests using this malloc descriptor.  For memory
-     mapped regions, this is the mmap() based routine.  There may also be
-     a single malloc descriptor that points to an sbrk() based routine
-     for systems without mmap() or for applications that call the mmalloc()
-     package with a NULL malloc descriptor.
-
-     FIXME:  For mapped regions shared by more than one process, this
-     needs to be maintained on a per-process basis. */
-  void *(*morecore) (struct mdesc * mdp, int size);
-
   /* Number of info entries.  */
   size_t heapsize;
 
@@ -268,6 +257,11 @@ extern void *__mmalloc_mmap_morecore(struct mdesc *mdp, int size);
 
 extern void *__mmalloc_remap_core(struct mdesc *mdp);
 
+/*  Get core for the memory region specified by MDP, using SIZE as the
+    amount to either add to or subtract from the existing region.  Works
+    like sbrk(), but using mmap(). */
+extern void *mmorecore(struct mdesc *mdp, int size);
+
 /* Macro to convert from a user supplied malloc descriptor to pointer to the
    internal malloc descriptor.  If the user supplied descriptor is NULL, then
    use the default internal version, initializing it if necessary.  Otherwise