annotate libsanitizer/tsan/tsan_mutexset.h @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
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 //
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
4 // See https://llvm.org/LICENSE.txt for license information.
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
111
kono
parents:
diff changeset
6 //
kono
parents:
diff changeset
7 //===----------------------------------------------------------------------===//
kono
parents:
diff changeset
8 //
kono
parents:
diff changeset
9 // This file is a part of ThreadSanitizer (TSan), a race detector.
kono
parents:
diff changeset
10 //
kono
parents:
diff changeset
11 // MutexSet holds the set of mutexes currently held by a thread.
kono
parents:
diff changeset
12 //===----------------------------------------------------------------------===//
kono
parents:
diff changeset
13 #ifndef TSAN_MUTEXSET_H
kono
parents:
diff changeset
14 #define TSAN_MUTEXSET_H
kono
parents:
diff changeset
15
kono
parents:
diff changeset
16 #include "tsan_defs.h"
kono
parents:
diff changeset
17
kono
parents:
diff changeset
18 namespace __tsan {
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 class MutexSet {
kono
parents:
diff changeset
21 public:
kono
parents:
diff changeset
22 // Holds limited number of mutexes.
kono
parents:
diff changeset
23 // The oldest mutexes are discarded on overflow.
kono
parents:
diff changeset
24 static const uptr kMaxSize = 16;
kono
parents:
diff changeset
25 struct Desc {
kono
parents:
diff changeset
26 u64 id;
kono
parents:
diff changeset
27 u64 epoch;
kono
parents:
diff changeset
28 int count;
kono
parents:
diff changeset
29 bool write;
kono
parents:
diff changeset
30 };
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 MutexSet();
kono
parents:
diff changeset
33 // The 'id' is obtained from SyncVar::GetId().
kono
parents:
diff changeset
34 void Add(u64 id, bool write, u64 epoch);
kono
parents:
diff changeset
35 void Del(u64 id, bool write);
kono
parents:
diff changeset
36 void Remove(u64 id); // Removes the mutex completely (if it's destroyed).
kono
parents:
diff changeset
37 uptr Size() const;
kono
parents:
diff changeset
38 Desc Get(uptr i) const;
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 void operator=(const MutexSet &other) {
kono
parents:
diff changeset
41 internal_memcpy(this, &other, sizeof(*this));
kono
parents:
diff changeset
42 }
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 private:
kono
parents:
diff changeset
45 #if !SANITIZER_GO
kono
parents:
diff changeset
46 uptr size_;
kono
parents:
diff changeset
47 Desc descs_[kMaxSize];
kono
parents:
diff changeset
48 #endif
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 void RemovePos(uptr i);
kono
parents:
diff changeset
51 MutexSet(const MutexSet&);
kono
parents:
diff changeset
52 };
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 // Go does not have mutexes, so do not spend memory and time.
kono
parents:
diff changeset
55 // (Go sync.Mutex is actually a semaphore -- can be unlocked
kono
parents:
diff changeset
56 // in different goroutine).
kono
parents:
diff changeset
57 #if SANITIZER_GO
kono
parents:
diff changeset
58 MutexSet::MutexSet() {}
kono
parents:
diff changeset
59 void MutexSet::Add(u64 id, bool write, u64 epoch) {}
kono
parents:
diff changeset
60 void MutexSet::Del(u64 id, bool write) {}
kono
parents:
diff changeset
61 void MutexSet::Remove(u64 id) {}
kono
parents:
diff changeset
62 void MutexSet::RemovePos(uptr i) {}
kono
parents:
diff changeset
63 uptr MutexSet::Size() const { return 0; }
kono
parents:
diff changeset
64 MutexSet::Desc MutexSet::Get(uptr i) const { return Desc(); }
kono
parents:
diff changeset
65 #endif
kono
parents:
diff changeset
66
kono
parents:
diff changeset
67 } // namespace __tsan
kono
parents:
diff changeset
68
kono
parents:
diff changeset
69 #endif // TSAN_MUTEXSET_H