]>
Commit | Line | Data |
---|---|---|
f5ed5428 | 1 | //===-- tsan_mutexset.h -----------------------------------------*- C++ -*-===// |
2 | // | |
2fc4da48 | 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 | |
f5ed5428 | 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 | ||
18 | namespace __tsan { | |
19 | ||
20 | class MutexSet { | |
21 | public: | |
22 | // Holds limited number of mutexes. | |
23 | // The oldest mutexes are discarded on overflow. | |
1e80ce41 | 24 | static const uptr kMaxSize = 16; |
f5ed5428 | 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 | ||
7d752f28 | 40 | void operator=(const MutexSet &other) { |
41 | internal_memcpy(this, &other, sizeof(*this)); | |
42 | } | |
43 | ||
f5ed5428 | 44 | private: |
23e39437 | 45 | #if !SANITIZER_GO |
f5ed5428 | 46 | uptr size_; |
47 | Desc descs_[kMaxSize]; | |
48 | #endif | |
49 | ||
50 | void RemovePos(uptr i); | |
7d752f28 | 51 | MutexSet(const MutexSet&); |
f5ed5428 | 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). | |
23e39437 | 57 | #if SANITIZER_GO |
f5ed5428 | 58 | MutexSet::MutexSet() {} |
59 | void MutexSet::Add(u64 id, bool write, u64 epoch) {} | |
60 | void MutexSet::Del(u64 id, bool write) {} | |
61 | void MutexSet::Remove(u64 id) {} | |
62 | void MutexSet::RemovePos(uptr i) {} | |
63 | uptr MutexSet::Size() const { return 0; } | |
64 | MutexSet::Desc MutexSet::Get(uptr i) const { return Desc(); } | |
65 | #endif | |
66 | ||
67 | } // namespace __tsan | |
68 | ||
4fc7b5ac | 69 | #endif // TSAN_MUTEXSET_H |