]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/scudo/scudo_tsd_shared.inc
Merge OpenSSL 1.0.2o.
[FreeBSD/FreeBSD.git] / contrib / compiler-rt / lib / scudo / scudo_tsd_shared.inc
1 //===-- scudo_tsd_shared.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 shared 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 extern pthread_key_t PThreadKey;
21
22 ALWAYS_INLINE ScudoTSD* getCurrentTSD() {
23 #if SANITIZER_ANDROID
24   return reinterpret_cast<ScudoTSD *>(*get_android_tls_ptr());
25 #else
26   return reinterpret_cast<ScudoTSD *>(pthread_getspecific(PThreadKey));
27 #endif  // SANITIZER_ANDROID
28 }
29
30 ALWAYS_INLINE void initThreadMaybe(bool MinimalInit = false) {
31   if (LIKELY(getCurrentTSD()))
32     return;
33   initThread(MinimalInit);
34 }
35
36 ScudoTSD *getTSDAndLockSlow();
37
38 ALWAYS_INLINE ScudoTSD *getTSDAndLock() {
39   ScudoTSD *TSD = getCurrentTSD();
40   CHECK(TSD && "No TSD associated with the current thread!");
41   // Try to lock the currently associated context.
42   if (TSD->tryLock())
43     return TSD;
44   // If it failed, go the slow path.
45   return getTSDAndLockSlow();
46 }
47
48 #endif  // !SCUDO_TSD_EXCLUSIVE