]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/scudo/scudo_tsd_exclusive.inc
Merge compiler-rt trunk r321017 to contrib/compiler-rt.
[FreeBSD/FreeBSD.git] / contrib / compiler-rt / lib / scudo / scudo_tsd_exclusive.inc
1 //===-- scudo_tsd_exclusive.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 /// Scudo exclusive TSD fastpath functions implementation.
11 ///
12 //===----------------------------------------------------------------------===//
13
14 #ifndef SCUDO_TSD_H_
15 # error "This file must be included inside scudo_tsd.h."
16 #endif  // SCUDO_TSD_H_
17
18 #if SCUDO_TSD_EXCLUSIVE
19
20 enum ThreadState : u8 {
21   ThreadNotInitialized = 0,
22   ThreadInitialized,
23   ThreadTornDown,
24 };
25 __attribute__((tls_model("initial-exec")))
26 extern THREADLOCAL ThreadState ScudoThreadState;
27 __attribute__((tls_model("initial-exec")))
28 extern THREADLOCAL ScudoTSD TSD;
29
30 extern ScudoTSD FallbackTSD;
31
32 ALWAYS_INLINE void initThreadMaybe(bool MinimalInit = false) {
33   if (LIKELY(ScudoThreadState != ThreadNotInitialized))
34     return;
35   initThread(MinimalInit);
36 }
37
38 ALWAYS_INLINE ScudoTSD *getTSDAndLock() {
39   if (UNLIKELY(ScudoThreadState != ThreadInitialized)) {
40     FallbackTSD.lock();
41     return &FallbackTSD;
42   }
43   return &TSD;
44 }
45
46 #endif  // SCUDO_TSD_EXCLUSIVE