2013-02-04 Paul Thomas <pault@gcc.gnu.org>
[official-gcc.git] / libsanitizer / tsan / tsan_mutex.h
blob6d1450593301d6bd0129b855d48ad38154563f19
1 //===-- tsan_mutex.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 //===----------------------------------------------------------------------===//
11 #ifndef TSAN_MUTEX_H
12 #define TSAN_MUTEX_H
14 #include "sanitizer_common/sanitizer_atomic.h"
15 #include "sanitizer_common/sanitizer_mutex.h"
16 #include "tsan_defs.h"
18 namespace __tsan {
20 enum MutexType {
21 MutexTypeInvalid,
22 MutexTypeTrace,
23 MutexTypeThreads,
24 MutexTypeReport,
25 MutexTypeSyncVar,
26 MutexTypeSyncTab,
27 MutexTypeSlab,
28 MutexTypeAnnotations,
29 MutexTypeAtExit,
30 MutexTypeMBlock,
31 MutexTypeJavaMBlock,
33 // This must be the last.
34 MutexTypeCount
37 class Mutex {
38 public:
39 explicit Mutex(MutexType type, StatType stat_type);
40 ~Mutex();
42 void Lock();
43 void Unlock();
45 void ReadLock();
46 void ReadUnlock();
48 void CheckLocked();
50 private:
51 atomic_uintptr_t state_;
52 #if TSAN_DEBUG
53 MutexType type_;
54 #endif
55 #if TSAN_COLLECT_STATS
56 StatType stat_type_;
57 #endif
59 Mutex(const Mutex&);
60 void operator = (const Mutex&);
63 typedef GenericScopedLock<Mutex> Lock;
64 typedef GenericScopedReadLock<Mutex> ReadLock;
66 class DeadlockDetector {
67 public:
68 DeadlockDetector();
69 void Lock(MutexType t);
70 void Unlock(MutexType t);
71 private:
72 u64 seq_;
73 u64 locked_[MutexTypeCount];
76 void InitializeMutex();
78 } // namespace __tsan
80 #endif // TSAN_MUTEX_H