00001
00002
00003 #define MEM_LOCK_AROUND(code) \
00004 CmiMemLock(); \
00005 code; \
00006 CmiMemUnlock();
00007
00008
00009 #define REENTRANT_MEM_LOCK_AROUND(code) \
00010 int myRank=CmiMyRank(); \
00011 if (myRank!=rank_holding_CmiMemLock) { \
00012 CmiMemLock(); \
00013 rank_holding_CmiMemLock=myRank; \
00014 code; \
00015 rank_holding_CmiMemLock=-1; \
00016 CmiMemUnlock(); \
00017 } \
00018 else { \
00019 code; \
00020 }
00021
00022 static void meta_init(char **argv)
00023 {
00024
00025 }
00026
00027 void *meta_malloc(size_t size)
00028 {
00029 void *result;
00030 MEM_LOCK_AROUND( result = mm_malloc(size); )
00031 if (result==NULL) CmiOutOfMemory(size);
00032 return result;
00033 }
00034
00035 void meta_free(void *mem)
00036 {
00037 MEM_LOCK_AROUND( mm_free(mem); )
00038 }
00039
00040 void *meta_calloc(size_t nelem, size_t size)
00041 {
00042 void *result;
00043 MEM_LOCK_AROUND( result = mm_calloc(nelem, size); )
00044 if (result==NULL) CmiOutOfMemory(size);
00045 return result;
00046 }
00047
00048 void meta_cfree(void *mem)
00049 {
00050 MEM_LOCK_AROUND( mm_cfree(mem); )
00051 }
00052
00053 void *meta_realloc(void *mem, size_t size)
00054 {
00055 void *result;
00056 MEM_LOCK_AROUND( result = mm_realloc(mem, size); )
00057 return result;
00058 }
00059
00060 void *meta_memalign(size_t align, size_t size)
00061 {
00062 void *result;
00063 MEM_LOCK_AROUND( result = mm_memalign(align, size); )
00064 if (result==NULL) CmiOutOfMemory(align*size);
00065 return result;
00066 }
00067
00068 int meta_posix_memalign(void **outptr, size_t align, size_t size)
00069 {
00070 int result;
00071 MEM_LOCK_AROUND( result = mm_posix_memalign(outptr, align, size); )
00072 if (result!=0) CmiOutOfMemory(align*size);
00073 return result;
00074 }
00075
00076 void *meta_aligned_alloc(size_t align, size_t size)
00077 {
00078 void *result;
00079 MEM_LOCK_AROUND( result = mm_aligned_alloc(align, size); )
00080 if (result==NULL) CmiOutOfMemory(align*size);
00081 return result;
00082 }
00083
00084 void *meta_valloc(size_t size)
00085 {
00086 void *result;
00087 MEM_LOCK_AROUND( result = mm_valloc(size); )
00088 if (result==NULL) CmiOutOfMemory(size);
00089 return result;
00090 }
00091
00092 void *meta_pvalloc(size_t size)
00093 {
00094 void *result;
00095 MEM_LOCK_AROUND( result = mm_pvalloc(size); )
00096 if (result==NULL) CmiOutOfMemory(size);
00097 return result;
00098 }