[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [52906] trunk/blender/intern/guardedalloc: assert in debug builds if MEM_ alloc's are called in openmp threads.
Campbell Barton
ideasman42 at gmail.com
Wed Dec 12 05:41:28 CET 2012
Revision: 52906
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=52906
Author: campbellbarton
Date: 2012-12-12 04:41:23 +0000 (Wed, 12 Dec 2012)
Log Message:
-----------
assert in debug builds if MEM_ alloc's are called in openmp threads.
note: the caller can do locking to prevent errors - but this isn't being done in blender yet, so this prevents accidental allocs in openmp for now.
Modified Paths:
--------------
trunk/blender/intern/guardedalloc/CMakeLists.txt
trunk/blender/intern/guardedalloc/SConscript
trunk/blender/intern/guardedalloc/intern/mallocn.c
Modified: trunk/blender/intern/guardedalloc/CMakeLists.txt
===================================================================
--- trunk/blender/intern/guardedalloc/CMakeLists.txt 2012-12-12 02:48:03 UTC (rev 52905)
+++ trunk/blender/intern/guardedalloc/CMakeLists.txt 2012-12-12 04:41:23 UTC (rev 52906)
@@ -46,6 +46,11 @@
)
endif()
+# only for debugging
+if(WITH_OPENMP)
+ add_definitions(-DPARALLEL=1)
+endif()
+
blender_add_lib(bf_intern_guardedalloc "${SRC}" "${INC}" "${INC_SYS}")
# Override C++ alloc, optional.
Modified: trunk/blender/intern/guardedalloc/SConscript
===================================================================
--- trunk/blender/intern/guardedalloc/SConscript 2012-12-12 02:48:03 UTC (rev 52905)
+++ trunk/blender/intern/guardedalloc/SConscript 2012-12-12 04:41:23 UTC (rev 52906)
@@ -12,4 +12,9 @@
incs = '.'
+if env['WITH_BF_OPENMP']:
+ if env['OURPLATFORM'] == 'linuxcross':
+ incs += ' ' + env['BF_OPENMP_INC']
+ defs.append('PARALLEL=1')
+
env.BlenderLib ('bf_intern_guardedalloc', sources, Split(incs), defs, libtype=['intern','player'], priority = [5,150] )
Modified: trunk/blender/intern/guardedalloc/intern/mallocn.c
===================================================================
--- trunk/blender/intern/guardedalloc/intern/mallocn.c 2012-12-12 02:48:03 UTC (rev 52905)
+++ trunk/blender/intern/guardedalloc/intern/mallocn.c 2012-12-12 04:41:23 UTC (rev 52906)
@@ -110,6 +110,15 @@
#endif
} MemHead;
+/* for openmp threading asserts, saves time troubleshooting
+ * we may need to extend this if blender code starts using MEM_
+ * functions inside OpenMP correctly with omp_set_lock() */
+#if (PARALLEL == 1) && defined(DEBUG)
+# include <assert.h>
+# include <omp.h>
+# define DEBUG_OMP_MALLOC
+#endif
+
typedef struct MemTail {
int tag3, pad;
} MemTail;
@@ -194,6 +203,10 @@
static void mem_lock_thread(void)
{
+#ifdef DEBUG_OMP_MALLOC
+ assert(omp_in_parallel() == 0);
+#endif
+
if (thread_lock_callback)
thread_lock_callback();
}
@@ -214,8 +227,7 @@
err_val = check_memlist(listend);
- if (err_val == NULL) return 0;
- return 1;
+ return (err_val != NULL);
}
More information about the Bf-blender-cvs
mailing list