forked from weaselab/conflict-set
Add valgrind annotations
This appears to affect the binary (how else could it possibly work??), but the microbenchmarks don't show a difference
This commit is contained in:
+19
-2
@@ -36,6 +36,11 @@ limitations under the License.
|
||||
#include <arm_neon.h>
|
||||
#endif
|
||||
|
||||
#if __has_include(<valgrind/memcheck.h>)
|
||||
#define MEMCHECK
|
||||
#include <valgrind/memcheck.h>
|
||||
#endif
|
||||
|
||||
// ==================== BEGIN IMPLEMENTATION ====================
|
||||
|
||||
struct Entry {
|
||||
@@ -53,10 +58,16 @@ struct BoundedFreeListAllocator {
|
||||
return new (safe_malloc(sizeof(T))) T;
|
||||
}
|
||||
assert(freeList != nullptr);
|
||||
void *result = freeList;
|
||||
void *buffer = freeList;
|
||||
#ifdef MEMCHECK
|
||||
VALGRIND_MAKE_MEM_DEFINED(freeList, sizeof(freeList));
|
||||
#endif
|
||||
memcpy(&freeList, freeList, sizeof(freeList));
|
||||
--freeListSize;
|
||||
return new (result) T;
|
||||
#ifdef MEMCHECK
|
||||
VALGRIND_MAKE_MEM_UNDEFINED(buffer, sizeof(T));
|
||||
#endif
|
||||
return new (buffer) T;
|
||||
}
|
||||
|
||||
void release(T *p) {
|
||||
@@ -67,10 +78,16 @@ struct BoundedFreeListAllocator {
|
||||
memcpy((void *)p, &freeList, sizeof(freeList));
|
||||
freeList = p;
|
||||
++freeListSize;
|
||||
#ifdef MEMCHECK
|
||||
VALGRIND_MAKE_MEM_NOACCESS(p, sizeof(T));
|
||||
#endif
|
||||
}
|
||||
|
||||
~BoundedFreeListAllocator() {
|
||||
for (void *iter = freeList; iter != nullptr;) {
|
||||
#ifdef MEMCHECK
|
||||
VALGRIND_MAKE_MEM_DEFINED(iter, sizeof(iter));
|
||||
#endif
|
||||
auto *tmp = iter;
|
||||
memcpy(&iter, iter, sizeof(void *));
|
||||
free(tmp);
|
||||
|
||||
Reference in New Issue
Block a user