a new memory lock scheme which wrap os malloc with locking.
authorGengbin Zheng <gzheng@illinois.edu>
Fri, 30 May 2008 14:28:06 +0000 (14:28 +0000)
committerGengbin Zheng <gzheng@illinois.edu>
Fri, 30 May 2008 14:28:06 +0000 (14:28 +0000)
src/conv-core/memory-lock.c [new file with mode: 0644]
src/conv-core/memory.c

diff --git a/src/conv-core/memory-lock.c b/src/conv-core/memory-lock.c
new file mode 100644 (file)
index 0000000..4383434
--- /dev/null
@@ -0,0 +1,74 @@
+
+/* Wrap a CmiMemLock around this code */
+#define MEM_LOCK_AROUND(code) \
+  CmiMemLock(); \
+  code; \
+  CmiMemUnlock();
+
+/* Wrap a reentrant CmiMemLock around this code */
+#define REENTRANT_MEM_LOCK_AROUND(code) \
+  int myRank=CmiMyRank(); \
+  if (myRank!=rank_holding_CmiMemLock) { \
+       CmiMemLock(); \
+       rank_holding_CmiMemLock=myRank; \
+       code; \
+       rank_holding_CmiMemLock=-1; \
+       CmiMemUnlock(); \
+  } \
+  else /* I'm already holding the memLock (reentrancy) */ { \
+       code; \
+  }
+
+static void meta_init(char **argv)
+{
+/*   CmiMemoryIs_flag|=CMI_MEMORY_IS_OSLOCK;   */
+}
+
+void *meta_malloc(size_t size)
+{
+  void *result;
+  MEM_LOCK_AROUND( result = mm_malloc(size); )
+  if (result==NULL) CmiOutOfMemory(size);
+  return result;
+}
+
+void meta_free(void *mem)
+{
+  MEM_LOCK_AROUND( mm_free(mem); )
+}
+
+void *meta_calloc(size_t nelem, size_t size)
+{
+  void *result;
+  MEM_LOCK_AROUND( result = mm_calloc(nelem, size); )
+  if (result==NULL) CmiOutOfMemory(size);
+  return result;
+}
+
+void meta_cfree(void *mem)
+{
+  MEM_LOCK_AROUND( mm_cfree(mem); )
+}
+
+void *meta_realloc(void *mem, size_t size)
+{
+  void *result;
+  MEM_LOCK_AROUND( result = mm_realloc(mem, size); )
+  return result;
+}
+
+void *meta_memalign(size_t align, size_t size)
+{
+  void *result;
+  MEM_LOCK_AROUND( result = mm_memalign(align, size); )
+  if (result==NULL) CmiOutOfMemory(align*size);
+  return result;    
+}
+
+void *meta_valloc(size_t size)
+{
+  void *result;
+  MEM_LOCK_AROUND( result = mm_valloc(size); )
+  if (result==NULL) CmiOutOfMemory(size);
+  return result;
+}
index 57860dbf6511a044fb35f4ba563552709415dc0a..a4c6167fdbf40900fbe5c39e79f0880859588a41 100644 (file)
@@ -192,6 +192,10 @@ int memory_chare_id=0;
 #include "memory-isomalloc.c"
 #endif 
 
+#if CMK_MEMORY_BUILD_LOCK
+#include "memory-lock.c"
+#endif 
+
 #if CMK_MEMORY_BUILD_CHARMDEBUG
 #include "memory-charmdebug.c"
 #endif