1 //===-- scudo_tsd.h ---------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 /// Scudo thread specific data definition.
11 /// Implementation will differ based on the thread local storage primitives
12 /// offered by the underlying platform.
14 //===----------------------------------------------------------------------===//
19 #include "scudo_allocator.h"
20 #include "scudo_utils.h"
26 struct ALIGNED(SANITIZER_CACHE_LINE_SIZE) ScudoTSD {
27 AllocatorCacheT Cache;
28 uptr QuarantineCachePlaceHolder[4];
33 INLINE bool tryLock() {
34 if (Mutex.TryLock()) {
35 atomic_store_relaxed(&Precedence, 0);
38 if (atomic_load_relaxed(&Precedence) == 0)
39 atomic_store_relaxed(&Precedence, static_cast<uptr>(
40 MonotonicNanoTime() >> FIRST_32_SECOND_64(16, 0)));
45 atomic_store_relaxed(&Precedence, 0);
49 INLINE void unlock() { Mutex.Unlock(); }
51 INLINE uptr getPrecedence() { return atomic_load_relaxed(&Precedence); }
54 StaticSpinMutex Mutex;
55 atomic_uintptr_t Precedence;
58 void initThread(bool MinimalInit);
60 // TSD model specific fastpath functions definitions.
61 #include "scudo_tsd_exclusive.inc"
62 #include "scudo_tsd_shared.inc"
64 } // namespace __scudo
66 #endif // SCUDO_TSD_H_