1 //===-- tsan_mutexset.h -----------------------------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file is a part of ThreadSanitizer (TSan), a race detector.
11 //
12 // MutexSet holds the set of mutexes currently held by a thread.
13 //===----------------------------------------------------------------------===//
14 #ifndef TSAN_MUTEXSET_H
15 #define TSAN_MUTEXSET_H
16
17 #include "tsan_defs.h"
18
19 namespace __tsan {
20
21 class MutexSet {
22 public:
23 // Holds limited number of mutexes.
24 // The oldest mutexes are discarded on overflow.
25 static const uptr kMaxSize = 16;
26 struct Desc {
27 u64 id;
28 u64 epoch;
29 int count;
30 bool write;
31 };
32
33 MutexSet();
34 // The 'id' is obtained from SyncVar::GetId().
35 void Add(u64 id, bool write, u64 epoch);
36 void Del(u64 id, bool write);
37 void Remove(u64 id); // Removes the mutex completely (if it's destroyed).
38 uptr Size() const;
39 Desc Get(uptr i) const;
40
41 void operator=(const MutexSet &other) {
42 internal_memcpy(this, &other, sizeof(*this));
43 }
44
45 private:
46 #ifndef SANITIZER_GO
47 uptr size_;
48 Desc descs_[kMaxSize];
49 #endif
50
51 void RemovePos(uptr i);
52 MutexSet(const MutexSet&);
53 };
54
55 // Go does not have mutexes, so do not spend memory and time.
56 // (Go sync.Mutex is actually a semaphore -- can be unlocked
57 // in different goroutine).
58 #ifdef SANITIZER_GO
MutexSet()59 MutexSet::MutexSet() {}
Add(u64 id,bool write,u64 epoch)60 void MutexSet::Add(u64 id, bool write, u64 epoch) {}
Del(u64 id,bool write)61 void MutexSet::Del(u64 id, bool write) {}
Remove(u64 id)62 void MutexSet::Remove(u64 id) {}
RemovePos(uptr i)63 void MutexSet::RemovePos(uptr i) {}
Size()64 uptr MutexSet::Size() const { return 0; }
Get(uptr i)65 MutexSet::Desc MutexSet::Get(uptr i) const { return Desc(); }
66 #endif
67
68 } // namespace __tsan
69
70 #endif // TSAN_MUTEXSET_H
71