[PR67828] don't unswitch on default defs of non-parms
[official-gcc.git] / libsanitizer / tsan / tsan_mutex.h
blobc27bc2b4459c24e99d4cbae5d675a1707efe42b0
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,
34 // This must be the last.
35 MutexTypeCount
38 class Mutex {
39 public:
40 explicit Mutex(MutexType type, StatType stat_type);
41 ~Mutex();
43 void Lock();
44 void Unlock();
46 void ReadLock();
47 void ReadUnlock();
49 void CheckLocked();
51 private:
52 atomic_uintptr_t state_;
53 #if TSAN_DEBUG
54 MutexType type_;
55 #endif
56 #if TSAN_COLLECT_STATS
57 StatType stat_type_;
58 #endif
60 Mutex(const Mutex&);
61 void operator = (const Mutex&);
64 typedef GenericScopedLock<Mutex> Lock;
65 typedef GenericScopedReadLock<Mutex> ReadLock;
67 class InternalDeadlockDetector {
68 public:
69 InternalDeadlockDetector();
70 void Lock(MutexType t);
71 void Unlock(MutexType t);
72 void CheckNoLocks();
73 private:
74 u64 seq_;
75 u64 locked_[MutexTypeCount];
78 void InitializeMutex();
80 // Checks that the current thread does not hold any runtime locks
81 // (e.g. when returning from an interceptor).
82 void CheckNoLocks(ThreadState *thr);
84 } // namespace __tsan
86 #endif // TSAN_MUTEX_H