aboutsummaryrefslogtreecommitdiff
path: root/lib/sanitizer_common/sanitizer_mutex.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sanitizer_common/sanitizer_mutex.h')
-rw-r--r--lib/sanitizer_common/sanitizer_mutex.h31
1 files changed, 27 insertions, 4 deletions
diff --git a/lib/sanitizer_common/sanitizer_mutex.h b/lib/sanitizer_common/sanitizer_mutex.h
index ca3e2f9a4839..56438fce471c 100644
--- a/lib/sanitizer_common/sanitizer_mutex.h
+++ b/lib/sanitizer_common/sanitizer_mutex.h
@@ -20,18 +20,22 @@
namespace __sanitizer {
-class SpinMutex {
+class StaticSpinMutex {
public:
- SpinMutex() {
+ void Init() {
atomic_store(&state_, 0, memory_order_relaxed);
}
void Lock() {
- if (atomic_exchange(&state_, 1, memory_order_acquire) == 0)
+ if (TryLock())
return;
LockSlow();
}
+ bool TryLock() {
+ return atomic_exchange(&state_, 1, memory_order_acquire) == 0;
+ }
+
void Unlock() {
atomic_store(&state_, 0, memory_order_release);
}
@@ -50,11 +54,29 @@ class SpinMutex {
return;
}
}
+};
+class SpinMutex : public StaticSpinMutex {
+ public:
+ SpinMutex() {
+ Init();
+ }
+
+ private:
SpinMutex(const SpinMutex&);
void operator=(const SpinMutex&);
};
+class BlockingMutex {
+ public:
+ explicit BlockingMutex(LinkerInitialized);
+ void Lock();
+ void Unlock();
+ private:
+ uptr opaque_storage_[10];
+ uptr owner_; // for debugging
+};
+
template<typename MutexType>
class GenericScopedLock {
public:
@@ -93,7 +115,8 @@ class GenericScopedReadLock {
void operator=(const GenericScopedReadLock&);
};
-typedef GenericScopedLock<SpinMutex> SpinMutexLock;
+typedef GenericScopedLock<StaticSpinMutex> SpinMutexLock;
+typedef GenericScopedLock<BlockingMutex> BlockingMutexLock;
} // namespace __sanitizer