diff options
Diffstat (limited to 'gnu/llvm/compiler-rt/lib/tsan/rtl/tsan_mutexset.cpp')
-rw-r--r-- | gnu/llvm/compiler-rt/lib/tsan/rtl/tsan_mutexset.cpp | 48 |
1 files changed, 20 insertions, 28 deletions
diff --git a/gnu/llvm/compiler-rt/lib/tsan/rtl/tsan_mutexset.cpp b/gnu/llvm/compiler-rt/lib/tsan/rtl/tsan_mutexset.cpp index 813fa3bca93..3a75b80ac30 100644 --- a/gnu/llvm/compiler-rt/lib/tsan/rtl/tsan_mutexset.cpp +++ b/gnu/llvm/compiler-rt/lib/tsan/rtl/tsan_mutexset.cpp @@ -10,66 +10,55 @@ // //===----------------------------------------------------------------------===// #include "tsan_mutexset.h" + +#include "sanitizer_common/sanitizer_placement_new.h" #include "tsan_rtl.h" namespace __tsan { -const uptr MutexSet::kMaxSize; - MutexSet::MutexSet() { - size_ = 0; - internal_memset(&descs_, 0, sizeof(descs_)); } -void MutexSet::Add(u64 id, bool write, u64 epoch) { +void MutexSet::Reset() { internal_memset(this, 0, sizeof(*this)); } + +void MutexSet::AddAddr(uptr addr, StackID stack_id, bool write) { // Look up existing mutex with the same id. for (uptr i = 0; i < size_; i++) { - if (descs_[i].id == id) { + if (descs_[i].addr == addr) { descs_[i].count++; - descs_[i].epoch = epoch; + descs_[i].seq = seq_++; return; } } // On overflow, find the oldest mutex and drop it. if (size_ == kMaxSize) { - u64 minepoch = (u64)-1; - u64 mini = (u64)-1; + uptr min = 0; for (uptr i = 0; i < size_; i++) { - if (descs_[i].epoch < minepoch) { - minepoch = descs_[i].epoch; - mini = i; - } + if (descs_[i].seq < descs_[min].seq) + min = i; } - RemovePos(mini); + RemovePos(min); CHECK_EQ(size_, kMaxSize - 1); } // Add new mutex descriptor. - descs_[size_].id = id; + descs_[size_].addr = addr; + descs_[size_].stack_id = stack_id; descs_[size_].write = write; - descs_[size_].epoch = epoch; + descs_[size_].seq = seq_++; descs_[size_].count = 1; size_++; } -void MutexSet::Del(u64 id, bool write) { +void MutexSet::DelAddr(uptr addr, bool destroy) { for (uptr i = 0; i < size_; i++) { - if (descs_[i].id == id) { - if (--descs_[i].count == 0) + if (descs_[i].addr == addr) { + if (destroy || --descs_[i].count == 0) RemovePos(i); return; } } } -void MutexSet::Remove(u64 id) { - for (uptr i = 0; i < size_; i++) { - if (descs_[i].id == id) { - RemovePos(i); - return; - } - } -} - void MutexSet::RemovePos(uptr i) { CHECK_LT(i, size_); descs_[i] = descs_[size_ - 1]; @@ -85,4 +74,7 @@ MutexSet::Desc MutexSet::Get(uptr i) const { return descs_[i]; } +DynamicMutexSet::DynamicMutexSet() : ptr_(New<MutexSet>()) {} +DynamicMutexSet::~DynamicMutexSet() { DestroyAndFree(ptr_); } + } // namespace __tsan |