Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2013-01-24 12:14:05 +0400
committerSergey Sharybin <sergey.vfx@gmail.com>2013-01-24 12:14:05 +0400
commit5e739ddae2cc5fdb30e62544bfdd5b55284962a5 (patch)
treef3a449a1d591513cd87a7671dbc0fa2bea556dc5 /intern/guardedalloc
parentc65c1958bde6425cedb810590d64252adc2e56c3 (diff)
Added some code which helps troubleshooting issues caused by
non-threadsafe usage of guarded allocator. Also added small chunk of code to check consistency of begin/end threaded malloc. All this additional checks are commented and wouldn't affect on builds, however found them helpful to troubleshoot issues so decided to commit it to SVN.
Diffstat (limited to 'intern/guardedalloc')
-rw-r--r--intern/guardedalloc/intern/mallocn.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/intern/guardedalloc/intern/mallocn.c b/intern/guardedalloc/intern/mallocn.c
index 11fa477c2a4..559d1138ffb 100644
--- a/intern/guardedalloc/intern/mallocn.c
+++ b/intern/guardedalloc/intern/mallocn.c
@@ -68,6 +68,17 @@
//#define DEBUG_MEMCOUNTER
+/* Only for debugging:
+ * defining DEBUG_THREADS will enable check whether memory manager
+ * is locked with a mutex when allocation is called from non-main
+ * thread.
+ *
+ * This helps troubleshooting memory issues caused by the fact
+ * guarded allocator is not thread-safe, however this check will
+ * fail to check allocations from openmp threads.
+ */
+//#define DEBUG_THREADS
+
#ifdef DEBUG_MEMCOUNTER
/* set this to the value that isn't being freed */
# define DEBUG_MEMCOUNTER_ERROR_VAL 0
@@ -122,6 +133,12 @@ typedef struct MemHead {
#endif
#endif
+#ifdef DEBUG_THREADS
+# include <assert.h>
+# include <pthread.h>
+static pthread_t mainid;
+#endif
+
typedef struct MemTail {
int tag3, pad;
} MemTail;
@@ -206,6 +223,20 @@ static void print_error(const char *str, ...)
static void mem_lock_thread(void)
{
+#ifdef DEBUG_THREADS
+ static int initialized = 0;
+
+ if (initialized == 0) {
+ /* assume first allocation happens from main thread */
+ mainid = pthread_self();
+ initialized = 1;
+ }
+
+ if (!pthread_equal(pthread_self(), mainid) && thread_lock_callback == NULL) {
+ assert(!"Memory function is called from non-main thread without lock");
+ }
+#endif
+
#ifdef DEBUG_OMP_MALLOC
assert(omp_in_parallel() == 0);
#endif