diff options
author | Dmitry Vyukov <dvyukov@google.com> | 2012-07-02 07:09:21 +0000 |
---|---|---|
committer | Dmitry Vyukov <dvyukov@google.com> | 2012-07-02 07:09:21 +0000 |
commit | b13099c26e3be1a072cb87bed79fbcc649572e97 (patch) | |
tree | f092f7170598520f5386824cf2624360a1f1dcdc /compiler-rt/lib | |
parent | 9784d093e132f96255c8c943bc082f772235e33a (diff) | |
download | bcm5719-llvm-b13099c26e3be1a072cb87bed79fbcc649572e97.tar.gz bcm5719-llvm-b13099c26e3be1a072cb87bed79fbcc649572e97.zip |
asan/tsan: improve SpinMutex
llvm-svn: 159518
Diffstat (limited to 'compiler-rt/lib')
-rw-r--r-- | compiler-rt/lib/sanitizer_common/sanitizer_mutex.h | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_mutex.h b/compiler-rt/lib/sanitizer_common/sanitizer_mutex.h index 6cc86d3f8fd..ca3e2f9a483 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_mutex.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_mutex.h @@ -14,8 +14,9 @@ #ifndef SANITIZER_MUTEX_H #define SANITIZER_MUTEX_H -#include "sanitizer_internal_defs.h" #include "sanitizer_atomic.h" +#include "sanitizer_internal_defs.h" +#include "sanitizer_libc.h" namespace __sanitizer { @@ -26,8 +27,9 @@ class SpinMutex { } void Lock() { - while (atomic_exchange(&state_, 1, memory_order_acquire)) - proc_yield(10); + if (atomic_exchange(&state_, 1, memory_order_acquire) == 0) + return; + LockSlow(); } void Unlock() { @@ -37,6 +39,18 @@ class SpinMutex { private: atomic_uint8_t state_; + void NOINLINE LockSlow() { + for (int i = 0;; i++) { + if (i < 10) + proc_yield(10); + else + internal_sched_yield(); + if (atomic_load(&state_, memory_order_relaxed) == 0 + && atomic_exchange(&state_, 1, memory_order_acquire) == 0) + return; + } + } + SpinMutex(const SpinMutex&); void operator=(const SpinMutex&); }; |