[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [60556] trunk/blender/source/blender/ blenlib/intern: use valgrind hints for memarena for better debugging info when using valgrind .
Campbell Barton
ideasman42 at gmail.com
Sat Oct 5 06:38:08 CEST 2013
Revision: 60556
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=60556
Author: campbellbarton
Date: 2013-10-05 04:38:08 +0000 (Sat, 05 Oct 2013)
Log Message:
-----------
use valgrind hints for memarena for better debugging info when using valgrind.
also quiet a false positive in BLI_mempool_free().
Modified Paths:
--------------
trunk/blender/source/blender/blenlib/intern/BLI_memarena.c
trunk/blender/source/blender/blenlib/intern/BLI_mempool.c
Modified: trunk/blender/source/blender/blenlib/intern/BLI_memarena.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/BLI_memarena.c 2013-10-04 18:34:28 UTC (rev 60555)
+++ trunk/blender/source/blender/blenlib/intern/BLI_memarena.c 2013-10-05 04:38:08 UTC (rev 60556)
@@ -38,6 +38,10 @@
#include "BLI_linklist.h"
#include "BLI_strict_flags.h"
+#ifdef WITH_MEM_VALGRIND
+# include "valgrind/memcheck.h"
+#endif
+
struct MemArena {
unsigned char *curbuf;
int bufsize, cursize;
@@ -56,6 +60,10 @@
ma->align = 8;
ma->name = name;
+#ifdef WITH_MEM_VALGRIND
+ VALGRIND_CREATE_MEMPOOL(ma, 0, false);
+#endif
+
return ma;
}
@@ -122,6 +130,10 @@
ma->curbuf += size;
ma->cursize -= size;
+#ifdef WITH_MEM_VALGRIND
+ VALGRIND_MEMPOOL_ALLOC(ma, ptr, size);
+#endif
+
return ptr;
}
@@ -152,4 +164,10 @@
memset(ma->curbuf, 0, (size_t)curbuf_used);
}
}
+
+#ifdef WITH_MEM_VALGRIND
+ VALGRIND_DESTROY_MEMPOOL(ma);
+ VALGRIND_CREATE_MEMPOOL(ma, 0, false);
+#endif
+
}
Modified: trunk/blender/source/blender/blenlib/intern/BLI_mempool.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/BLI_mempool.c 2013-10-04 18:34:28 UTC (rev 60555)
+++ trunk/blender/source/blender/blenlib/intern/BLI_mempool.c 2013-10-05 04:38:08 UTC (rev 60556)
@@ -366,8 +366,12 @@
pool->totused--;
+#ifdef WITH_MEM_VALGRIND
+ VALGRIND_MEMPOOL_FREE(pool, addr);
+#endif
+
/* nothing is in use; free all the chunks except the first */
- if (pool->totused == 0) {
+ if (UNLIKELY(pool->totused == 0)) {
BLI_freenode *curnode = NULL;
char *tmpaddr = NULL;
unsigned int i;
@@ -380,6 +384,10 @@
pool->totalloc = pool->pchunk;
#endif
+ /* temp alloc so valgrind doesn't complain when setting free'd blocks 'next' */
+#ifdef WITH_MEM_VALGRIND
+ VALGRIND_MEMPOOL_ALLOC(pool, CHUNK_DATA(first), pool->csize);
+#endif
pool->free = CHUNK_DATA(first); /* start of the list */
for (tmpaddr = CHUNK_DATA(first), i = 0; i < pool->pchunk; i++) {
curnode = ((BLI_freenode *)tmpaddr);
@@ -387,11 +395,11 @@
curnode->next = (BLI_freenode *)tmpaddr;
}
curnode->next = NULL; /* terminate the list */
- }
#ifdef WITH_MEM_VALGRIND
- VALGRIND_MEMPOOL_FREE(pool, addr);
+ VALGRIND_MEMPOOL_FREE(pool, CHUNK_DATA(first));
#endif
+ }
}
int BLI_mempool_count(BLI_mempool *pool)
More information about the Bf-blender-cvs
mailing list