1 //===-- scudo_tsd.h ---------------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 /// Scudo thread specific data definition.
10 /// Implementation will differ based on the thread local storage primitives
11 /// offered by the underlying platform.
13 //===----------------------------------------------------------------------===//
18 #include "scudo_allocator.h"
19 #include "scudo_utils.h"
25 struct ALIGNED(SANITIZER_CACHE_LINE_SIZE) ScudoTSD {
26 AllocatorCacheT Cache;
27 uptr QuarantineCachePlaceHolder[4];
32 INLINE bool tryLock() {
33 if (Mutex.TryLock()) {
34 atomic_store_relaxed(&Precedence, 0);
37 if (atomic_load_relaxed(&Precedence) == 0)
38 atomic_store_relaxed(&Precedence, static_cast<uptr>(
39 MonotonicNanoTime() >> FIRST_32_SECOND_64(16, 0)));
44 atomic_store_relaxed(&Precedence, 0);
48 INLINE void unlock() { Mutex.Unlock(); }
50 INLINE uptr getPrecedence() { return atomic_load_relaxed(&Precedence); }
53 StaticSpinMutex Mutex;
54 atomic_uintptr_t Precedence;
57 void initThread(bool MinimalInit);
59 // TSD model specific fastpath functions definitions.
60 #include "scudo_tsd_exclusive.inc"
61 #include "scudo_tsd_shared.inc"
63 } // namespace __scudo
65 #endif // SCUDO_TSD_H_