]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/scudo/scudo_tls_context_android.inc
MFV r316861: 6866 zdb -l should return non-zero if it fails to find any label
[FreeBSD/FreeBSD.git] / contrib / compiler-rt / lib / scudo / scudo_tls_context_android.inc
1 //===-- scudo_tls_context_android.inc ---------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// Android specific base thread context definition.
11 ///
12 //===----------------------------------------------------------------------===//
13
14 #ifndef SCUDO_TLS_CONTEXT_ANDROID_INC_
15 #define SCUDO_TLS_CONTEXT_ANDROID_INC_
16
17 #ifndef SCUDO_TLS_H_
18 # error "This file must be included inside scudo_tls.h."
19 #endif  // SCUDO_TLS_H_
20
21 #if SANITIZER_LINUX && SANITIZER_ANDROID
22
23 struct ScudoThreadContextPlatform {
24   INLINE bool tryLock() {
25     if (Mutex.TryLock()) {
26       atomic_store_relaxed(&SlowLockPrecedence, 0);
27       return true;
28     }
29     if (atomic_load_relaxed(&SlowLockPrecedence) == 0)
30       atomic_store_relaxed(&SlowLockPrecedence, NanoTime());
31     return false;
32   }
33
34   INLINE void lock() {
35     Mutex.Lock();
36     atomic_store_relaxed(&SlowLockPrecedence, 0);
37   }
38
39   INLINE void unlock() {
40     Mutex.Unlock();
41   }
42
43   INLINE u64 getSlowLockPrecedence() {
44     return atomic_load_relaxed(&SlowLockPrecedence);
45   }
46
47  private:
48   StaticSpinMutex Mutex;
49   atomic_uint64_t SlowLockPrecedence;
50 };
51
52 #endif  // SANITIZER_LINUX && SANITIZER_ANDROID
53
54 #endif  // SCUDO_TLS_CONTEXT_ANDROID_INC_