tsan_mutexset.h 1.8 KB

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