annotate libsanitizer/tsan/tsan_mutexset.h @ 118:fd00160c1b76

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