blob: 09223ff6cc481518179387a66571df83eac84ccd [file] [log] [blame]
Dmitry Vyukovfd5ebcd2012-12-06 12:16:15 +00001//===-- 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
19namespace __tsan {
20
21class MutexSet {
22 public:
23 // Holds limited number of mutexes.
24 // The oldest mutexes are discarded on overflow.
25 static const uptr kMaxSize = 64;
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 private:
42#ifndef TSAN_GO
43 uptr size_;
44 Desc descs_[kMaxSize];
45#endif
46
47 void RemovePos(uptr i);
48};
49
50// Go does not have mutexes, so do not spend memory and time.
51// (Go sync.Mutex is actually a semaphore -- can be unlocked
52// in different goroutine).
53#ifdef TSAN_GO
54MutexSet::MutexSet() {}
55void MutexSet::Add(u64 id, bool write, u64 epoch) {}
56void MutexSet::Del(u64 id, bool write) {}
57void MutexSet::Remove(u64 id) {}
58void MutexSet::RemovePos(uptr i) {}
59uptr MutexSet::Size() const { return 0; }
60MutexSet::Desc MutexSet::Get(uptr i) const { return Desc(); }
61#endif
62
63} // namespace __tsan
64
65#endif // TSAN_REPORT_H