Add hppa*-*-* to dg-error targets at line 5
[official-gcc.git] / libsanitizer / tsan / tsan_mutexset.cpp
blob3a75b80ac30ffad9ed8f149ec77f05557c4f80ba
1 //===-- tsan_mutexset.cpp -------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file is a part of ThreadSanitizer (TSan), a race detector.
11 //===----------------------------------------------------------------------===//
12 #include "tsan_mutexset.h"
14 #include "sanitizer_common/sanitizer_placement_new.h"
15 #include "tsan_rtl.h"
17 namespace __tsan {
19 MutexSet::MutexSet() {
22 void MutexSet::Reset() { internal_memset(this, 0, sizeof(*this)); }
24 void MutexSet::AddAddr(uptr addr, StackID stack_id, bool write) {
25 // Look up existing mutex with the same id.
26 for (uptr i = 0; i < size_; i++) {
27 if (descs_[i].addr == addr) {
28 descs_[i].count++;
29 descs_[i].seq = seq_++;
30 return;
33 // On overflow, find the oldest mutex and drop it.
34 if (size_ == kMaxSize) {
35 uptr min = 0;
36 for (uptr i = 0; i < size_; i++) {
37 if (descs_[i].seq < descs_[min].seq)
38 min = i;
40 RemovePos(min);
41 CHECK_EQ(size_, kMaxSize - 1);
43 // Add new mutex descriptor.
44 descs_[size_].addr = addr;
45 descs_[size_].stack_id = stack_id;
46 descs_[size_].write = write;
47 descs_[size_].seq = seq_++;
48 descs_[size_].count = 1;
49 size_++;
52 void MutexSet::DelAddr(uptr addr, bool destroy) {
53 for (uptr i = 0; i < size_; i++) {
54 if (descs_[i].addr == addr) {
55 if (destroy || --descs_[i].count == 0)
56 RemovePos(i);
57 return;
62 void MutexSet::RemovePos(uptr i) {
63 CHECK_LT(i, size_);
64 descs_[i] = descs_[size_ - 1];
65 size_--;
68 uptr MutexSet::Size() const {
69 return size_;
72 MutexSet::Desc MutexSet::Get(uptr i) const {
73 CHECK_LT(i, size_);
74 return descs_[i];
77 DynamicMutexSet::DynamicMutexSet() : ptr_(New<MutexSet>()) {}
78 DynamicMutexSet::~DynamicMutexSet() { DestroyAndFree(ptr_); }
80 } // namespace __tsan