Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
The semaphore doesn't need to be shared between processes.
[simgrid.git] / src / xbt / mmalloc / mm_module.c
index 8ec8e73..5cb6084 100644 (file)
@@ -125,7 +125,7 @@ xbt_mheap_t xbt_mheap_new(int fd, void *baseaddr)
            mdp = (struct mdesc *) mtemp.base;
            mdp->fd = fd;
            if(!mdp->refcount){
-             sem_init(&mdp->sem, 1, 1);
+              sem_init(&mdp->sem, 0, 1);
              mdp->refcount++;
            }
          }
@@ -143,7 +143,8 @@ xbt_mheap_t xbt_mheap_new(int fd, void *baseaddr)
     }
   }
 
-  /* If the user provided NULL BASEADDR then fail */
+  /* NULL is not a valid baseaddr as we cannot map anything there.
+     C'mon, user. Think! */
   if (baseaddr == NULL)
     return (NULL);
 
@@ -167,10 +168,8 @@ xbt_mheap_t xbt_mheap_new(int fd, void *baseaddr)
 
   if (mdp->fd < 0){
     mdp->flags |= MMALLOC_ANONYMOUS;
-    sem_init(&mdp->sem, 0, 1);
-  }else{
-    sem_init(&mdp->sem, 1, 1);
   }
+  sem_init(&mdp->sem, 0, 1);
   
   /* If we have not been passed a valid open file descriptor for the file
      to map to, then open /dev/zero and use that to map to. */
@@ -183,7 +182,8 @@ xbt_mheap_t xbt_mheap_new(int fd, void *baseaddr)
   if ((mbase = mmorecore(mdp, sizeof(mtemp))) != NULL) {
     memcpy(mbase, mdp, sizeof(mtemp));
   } else {
-    THROWF(system_error,0,"morecore failed to get some memory!");
+    fprintf(stderr, "morecore failed to get some more memory!\n");
+    abort();
   }
 
   /* Add the new heap to the linked list of heaps attached by mmalloc */