diff options
author | Kostya Serebryany <kcc@google.com> | 2013-01-23 11:41:33 +0000 |
---|---|---|
committer | Kostya Serebryany <kcc@gcc.gnu.org> | 2013-01-23 11:41:33 +0000 |
commit | 2660d12d0a69539959dc1f77648f9f29f5e0edf8 (patch) | |
tree | 80989bd161e60d01560788cb7427eb644b227884 /libsanitizer/sanitizer_common/sanitizer_mutex.h | |
parent | b39968989d6ae4289c01202c45268b5651d1c222 (diff) |
libsanitizer merge from upstream r173241
From-SVN: r195404
Diffstat (limited to 'libsanitizer/sanitizer_common/sanitizer_mutex.h')
-rw-r--r-- | libsanitizer/sanitizer_common/sanitizer_mutex.h | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/libsanitizer/sanitizer_common/sanitizer_mutex.h b/libsanitizer/sanitizer_common/sanitizer_mutex.h index a38a49ae242..27009118e62 100644 --- a/libsanitizer/sanitizer_common/sanitizer_mutex.h +++ b/libsanitizer/sanitizer_common/sanitizer_mutex.h @@ -25,11 +25,15 @@ class StaticSpinMutex { } 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); } @@ -61,6 +65,16 @@ class SpinMutex : public StaticSpinMutex { 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: @@ -100,6 +114,7 @@ class GenericScopedReadLock { }; typedef GenericScopedLock<StaticSpinMutex> SpinMutexLock; +typedef GenericScopedLock<BlockingMutex> BlockingMutexLock; } // namespace __sanitizer |