tsan/asan: add mutex to 64-bit allocator
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@159516 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/sanitizer_common/sanitizer_allocator64.h b/lib/sanitizer_common/sanitizer_allocator64.h
index 0bac237..1728a71 100644
--- a/lib/sanitizer_common/sanitizer_allocator64.h
+++ b/lib/sanitizer_common/sanitizer_allocator64.h
@@ -20,6 +20,7 @@
#include "sanitizer_common.h"
#include "sanitizer_internal_defs.h"
#include "sanitizer_libc.h"
+#include "sanitizer_mutex.h"
namespace __sanitizer {
@@ -152,7 +153,7 @@
};
struct RegionInfo {
- uptr mutex; // FIXME
+ SpinMutex mutex;
LifoListNode *free_list;
uptr allocated_user; // Bytes allocated for user memory.
uptr allocated_meta; // Bytes allocated for metadata.
@@ -216,7 +217,7 @@
void *AllocateBySizeClass(uptr class_id) {
CHECK_LT(class_id, kNumClasses);
RegionInfo *region = GetRegionInfo(class_id);
- // FIXME: Lock region->mutex;
+ SpinMutexLock l(®ion->mutex);
if (!region->free_list) {
region->free_list = PopulateFreeList(class_id, region);
}
@@ -227,7 +228,7 @@
void DeallocateBySizeClass(void *p, uptr class_id) {
RegionInfo *region = GetRegionInfo(class_id);
- // FIXME: Lock region->mutex;
+ SpinMutexLock l(®ion->mutex);
PushLifoList(®ion->free_list, reinterpret_cast<LifoListNode*>(p));
}
};
@@ -250,7 +251,7 @@
Header *h = GetHeader(res);
h->size = size;
{
- // FIXME: lock
+ SpinMutexLock l(&mutex_);
h->next = list_;
h->prev = 0;
if (list_)
@@ -264,7 +265,7 @@
Header *h = GetHeader(p);
uptr map_size = RoundUpMapSize(h->size);
{
- // FIXME: lock
+ SpinMutexLock l(&mutex_);
Header *prev = h->prev;
Header *next = h->next;
if (prev)
@@ -278,7 +279,7 @@
}
uptr TotalMemoryUsed() {
- // FIXME: lock
+ SpinMutexLock l(&mutex_);
uptr res = 0;
for (Header *l = list_; l; l = l->next) {
res += RoundUpMapSize(l->size);
@@ -289,7 +290,7 @@
bool PointerIsMine(void *p) {
// Fast check.
if ((reinterpret_cast<uptr>(p) % kPageSize) != 0) return false;
- // FIXME: lock
+ SpinMutexLock l(&mutex_);
for (Header *l = list_; l; l = l->next) {
if (GetUser(l) == p) return true;
}
@@ -321,7 +322,7 @@
}
Header *list_;
- uptr lock_; // FIXME
+ SpinMutex mutex_;
};
// This class implements a complete memory allocator by using two
diff --git a/lib/sanitizer_common/sanitizer_mutex.h b/lib/sanitizer_common/sanitizer_mutex.h
index 8bb9d36..6cc86d3 100644
--- a/lib/sanitizer_common/sanitizer_mutex.h
+++ b/lib/sanitizer_common/sanitizer_mutex.h
@@ -79,6 +79,8 @@
void operator=(const GenericScopedReadLock&);
};
+typedef GenericScopedLock<SpinMutex> SpinMutexLock;
+
} // namespace __sanitizer
#endif // SANITIZER_MUTEX_H