implemented new CmiIsomallocBlockListMallocAlign that used by memory isomalloc to...
authorGengbin Zheng <gzheng@illinois.edu>
Thu, 24 Sep 2009 16:54:20 +0000 (16:54 +0000)
committerGengbin Zheng <gzheng@illinois.edu>
Thu, 24 Sep 2009 16:54:20 +0000 (16:54 +0000)
implemented a real memalign that respects alignment argument.

src/conv-core/converse.h
src/conv-core/isomalloc.c
src/conv-core/memory-isomalloc.c

index a972ef3280d3a02a889b3edb929eee556c155b80..4c339890780f1f4787bade125c5961e415ab8217 100644 (file)
@@ -1146,7 +1146,8 @@ void CmiIsomallocBlockListPup(pup_er p,CmiIsomallocBlockList **l);
 void CmiIsomallocBlockListDelete(CmiIsomallocBlockList *l);
 
 /*Allocate/free a block from this blockList*/
-void *CmiIsomallocBlockListMalloc(CmiIsomallocBlockList *l,int nBytes);
+void *CmiIsomallocBlockListMalloc(CmiIsomallocBlockList *l,size_t nBytes);
+void *CmiIsomallocBlockListMallocAlign(CmiIsomallocBlockList *l,size_t align,size_t nBytes);
 void CmiIsomallocBlockListFree(void *doomedMallocedBlock);
 
 /****** CTH: THE LOW-LEVEL THREADS PACKAGE ******/
index 9bdaaaf9c74031497a1d859bcb431ba81e96c4ed..6adc67a7d0bd570b1998408faaa134983ecc7d62 100644 (file)
@@ -2231,14 +2231,12 @@ static void *_isomallocAlign(size_t align, size_t size, size_t reserved)
         ptr = CmiIsomalloc(s);
         ptr2align = (char*)ptr + reserved;
         if ((((CmiUInt8)ptr2align) % align) != 0) { /* misaligned */
-          CmiIsomallocBlock *blk = pointer2block(ptr);  /* store block */
-          int slot = blk->slot;
-          int length = blk->length;
+          CmiIsomallocBlock *blk = pointer2block(ptr);  /* save block */
+          CmiIsomallocBlock savedblk = *blk;
           ptr2align = ((CmiUInt8)((char*)ptr2align + align - 1)) & -((CmiInt8) align);
           ptr = ptr2align - reserved;
           blk = pointer2block(ptr);      /* restore block */
-          blk->slot = slot;
-          blk->length = length;
+          *blk = savedblk;
         }
        return ptr;
 }
@@ -2432,7 +2430,7 @@ void CmiIsomallocBlockListDelete(CmiIsomallocBlockList *l)
 }
 
 /*Allocate a block from this blockList*/
-void *CmiIsomallocBlockListMalloc(CmiIsomallocBlockList *l,int nBytes)
+void *CmiIsomallocBlockListMalloc(CmiIsomallocBlockList *l,size_t nBytes)
 {
        Slot *n; /*Newly created slot*/
        n=(Slot *)CmiIsomalloc(sizeof(Slot)+nBytes);
@@ -2444,6 +2442,19 @@ void *CmiIsomallocBlockListMalloc(CmiIsomallocBlockList *l,int nBytes)
        return Slot_toUser(n);
 }
 
+/*Allocate a block from this blockList with alighment */
+void *CmiIsomallocBlockListMallocAlign(CmiIsomallocBlockList *l,size_t align,size_t nBytes)
+{
+       Slot *n; /*Newly created slot*/
+       n=(Slot *)_isomallocAlign(align,sizeof(Slot)+nBytes,sizeof(Slot));
+       /*Link the new block into the circular blocklist*/
+       n->prev=l;
+       n->next=l->next;
+       l->next->prev=n;
+       l->next=n;
+       return Slot_toUser(n);
+}
+
 /*Remove this block from its list and memory*/
 void CmiIsomallocBlockListFree(void *block)
 {
index b8cc86a381bbefff1c7dba22360b18b5500c1608..111891ad5e91f464148be891844fb856ac98179e 100644 (file)
@@ -117,7 +117,22 @@ static void *meta_realloc(void *oldBuffer, size_t newSize)
 
 static void *meta_memalign(size_t align, size_t size)
 {
-       return meta_malloc(size);
+       void *ret=NULL;
+       if (CpvInitialized(isomalloc_blocklist) && CpvAccess(isomalloc_blocklist)) 
+       { /*Isomalloc a new block and link it in*/
+               ISOMALLOC_PUSH /*Disable isomalloc while inside isomalloc*/
+#if CMK_ISOMALLOC_EXCLUDE_FORTRAN_CALLS
+               if (CmiIsFortranLibraryCall()==1) {
+                 ret=mm_malloc(size);
+               }
+               else
+#endif
+                 ret=CmiIsomallocBlockListMallocAlign(pushed_blocklist,align,size);
+               ISOMALLOC_POP
+       }
+       else /*Just use regular malloc*/
+               ret=mm_malloc(size);
+       return ret;
 }
 
 static void *meta_valloc(size_t size)