diff options
Diffstat (limited to 'lib/sanitizer_common/sanitizer_mutex.h')
-rw-r--r-- | lib/sanitizer_common/sanitizer_mutex.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/sanitizer_common/sanitizer_mutex.h b/lib/sanitizer_common/sanitizer_mutex.h index c4e4f7f71..8bb9d3648 100644 --- a/lib/sanitizer_common/sanitizer_mutex.h +++ b/lib/sanitizer_common/sanitizer_mutex.h @@ -6,6 +6,10 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// +// +// This file is a part of ThreadSanitizer/AddressSanitizer runtime. +// +//===----------------------------------------------------------------------===// #ifndef SANITIZER_MUTEX_H #define SANITIZER_MUTEX_H @@ -15,6 +19,28 @@ namespace __sanitizer { +class SpinMutex { + public: + SpinMutex() { + atomic_store(&state_, 0, memory_order_relaxed); + } + + void Lock() { + while (atomic_exchange(&state_, 1, memory_order_acquire)) + proc_yield(10); + } + + void Unlock() { + atomic_store(&state_, 0, memory_order_release); + } + + private: + atomic_uint8_t state_; + + SpinMutex(const SpinMutex&); + void operator=(const SpinMutex&); +}; + template<typename MutexType> class GenericScopedLock { public: |