]> git.ipfire.org Git - thirdparty/gcc.git/blame - libsanitizer/tsan/tsan_mutexset.h
[Ada] Improved support for aspect alignment in CCG
[thirdparty/gcc.git] / libsanitizer / tsan / tsan_mutexset.h
CommitLineData
e9772e16
KS
1//===-- tsan_mutexset.h -----------------------------------------*- C++ -*-===//
2//
b667dd70
ML
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
e9772e16
KS
6//
7//===----------------------------------------------------------------------===//
8//
9// This file is a part of ThreadSanitizer (TSan), a race detector.
10//
11// MutexSet holds the set of mutexes currently held by a thread.
12//===----------------------------------------------------------------------===//
13#ifndef TSAN_MUTEXSET_H
14#define TSAN_MUTEXSET_H
15
16#include "tsan_defs.h"
17
18namespace __tsan {
19
20class MutexSet {
21 public:
22 // Holds limited number of mutexes.
23 // The oldest mutexes are discarded on overflow.
ef1b3fda 24 static const uptr kMaxSize = 16;
e9772e16
KS
25 struct Desc {
26 u64 id;
27 u64 epoch;
28 int count;
29 bool write;
30 };
31
32 MutexSet();
33 // The 'id' is obtained from SyncVar::GetId().
34 void Add(u64 id, bool write, u64 epoch);
35 void Del(u64 id, bool write);
36 void Remove(u64 id); // Removes the mutex completely (if it's destroyed).
37 uptr Size() const;
38 Desc Get(uptr i) const;
39
dee5ea7a
KS
40 void operator=(const MutexSet &other) {
41 internal_memcpy(this, &other, sizeof(*this));
42 }
43
e9772e16 44 private:
10189819 45#if !SANITIZER_GO
e9772e16
KS
46 uptr size_;
47 Desc descs_[kMaxSize];
48#endif
49
50 void RemovePos(uptr i);
dee5ea7a 51 MutexSet(const MutexSet&);
e9772e16
KS
52};
53
54// Go does not have mutexes, so do not spend memory and time.
55// (Go sync.Mutex is actually a semaphore -- can be unlocked
56// in different goroutine).
10189819 57#if SANITIZER_GO
e9772e16
KS
58MutexSet::MutexSet() {}
59void MutexSet::Add(u64 id, bool write, u64 epoch) {}
60void MutexSet::Del(u64 id, bool write) {}
61void MutexSet::Remove(u64 id) {}
62void MutexSet::RemovePos(uptr i) {}
63uptr MutexSet::Size() const { return 0; }
64MutexSet::Desc MutexSet::Get(uptr i) const { return Desc(); }
65#endif
66
67} // namespace __tsan
68
df77f0e4 69#endif // TSAN_MUTEXSET_H