Move general functions out of typedefs.h
[alexxy/gromacs.git] / src / gromacs / utility / smalloc.c
index 8e08a341072d9d848d2d44848eca7eed504f616e..41bfc63153553785980894516f6559b0ce128f4e 100644 (file)
 #include <dmalloc.h>
 #endif
 
+#include "thread_mpi/threads.h"
+
 #include "gromacs/utility/fatalerror.h"
 #ifdef PRINT_ALLOC_KB
 #include "gromacs/utility/gmxmpi.h"
 #endif
 
-#ifdef DEBUG
-#include "thread_mpi/threads.h"
+static gmx_bool            g_bOverAllocDD     = FALSE;
+static tMPI_Thread_mutex_t g_over_alloc_mutex = TMPI_THREAD_MUTEX_INITIALIZER;
 
+#ifdef DEBUG
 static void log_action(int bMal, const char *what, const char *file, int line,
                        int nelem, int size, void *ptr)
 {
@@ -358,3 +361,24 @@ void save_free_aligned(const char *name, const char *file, int line, void *ptr)
 #endif
     }
 }
+
+void set_over_alloc_dd(gmx_bool set)
+{
+    tMPI_Thread_mutex_lock(&g_over_alloc_mutex);
+    /* we just make sure that we don't set this at the same time.
+       We don't worry too much about reading this rarely-set variable */
+    g_bOverAllocDD = set;
+    tMPI_Thread_mutex_unlock(&g_over_alloc_mutex);
+}
+
+int over_alloc_dd(int n)
+{
+    if (g_bOverAllocDD)
+    {
+        return OVER_ALLOC_FAC*n + 100;
+    }
+    else
+    {
+        return n;
+    }
+}