* tree-cfg.c (verify_gimple_in_cfg): Call verify_location on the
[official-gcc.git] / libsanitizer / tsan / tsan_mutex.h
blobbd1000f0b29e1da28b3f26cbb9b9e2b3a0c9c877
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,
32 MutexTypeDDetector,
33 MutexTypeFired,
34 MutexTypeRacy,
35 MutexTypeGlobalProc,
37 // This must be the last.
38 MutexTypeCount
41 class Mutex {
42 public:
43 explicit Mutex(MutexType type, StatType stat_type);
44 ~Mutex();
46 void Lock();
47 void Unlock();
49 void ReadLock();
50 void ReadUnlock();
52 void CheckLocked();
54 private:
55 atomic_uintptr_t state_;
56 #if SANITIZER_DEBUG
57 MutexType type_;
58 #endif
59 #if TSAN_COLLECT_STATS
60 StatType stat_type_;
61 #endif
63 Mutex(const Mutex&);
64 void operator = (const Mutex&);
67 typedef GenericScopedLock<Mutex> Lock;
68 typedef GenericScopedReadLock<Mutex> ReadLock;
70 class InternalDeadlockDetector {
71 public:
72 InternalDeadlockDetector();
73 void Lock(MutexType t);
74 void Unlock(MutexType t);
75 void CheckNoLocks();
76 private:
77 u64 seq_;
78 u64 locked_[MutexTypeCount];
81 void InitializeMutex();
83 // Checks that the current thread does not hold any runtime locks
84 // (e.g. when returning from an interceptor).
85 void CheckNoLocks(ThreadState *thr);
87 } // namespace __tsan
89 #endif // TSAN_MUTEX_H