1*9880d681SAndroid Build Coastguard Worker //===- ThreadLocal.cpp - Thread Local Data ----------------------*- C++ -*-===// 2*9880d681SAndroid Build Coastguard Worker // 3*9880d681SAndroid Build Coastguard Worker // The LLVM Compiler Infrastructure 4*9880d681SAndroid Build Coastguard Worker // 5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source 6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details. 7*9880d681SAndroid Build Coastguard Worker // 8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 9*9880d681SAndroid Build Coastguard Worker // 10*9880d681SAndroid Build Coastguard Worker // This file implements the llvm::sys::ThreadLocal class. 11*9880d681SAndroid Build Coastguard Worker // 12*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 13*9880d681SAndroid Build Coastguard Worker 14*9880d681SAndroid Build Coastguard Worker #include "llvm/Config/config.h" 15*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/Compiler.h" 16*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/ThreadLocal.h" 17*9880d681SAndroid Build Coastguard Worker 18*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 19*9880d681SAndroid Build Coastguard Worker //=== WARNING: Implementation here must contain only TRULY operating system 20*9880d681SAndroid Build Coastguard Worker //=== independent code. 21*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 22*9880d681SAndroid Build Coastguard Worker 23*9880d681SAndroid Build Coastguard Worker #if !defined(LLVM_ENABLE_THREADS) || LLVM_ENABLE_THREADS == 0 24*9880d681SAndroid Build Coastguard Worker // Define all methods as no-ops if threading is explicitly disabled 25*9880d681SAndroid Build Coastguard Worker namespace llvm { 26*9880d681SAndroid Build Coastguard Worker using namespace sys; ThreadLocalImpl()27*9880d681SAndroid Build Coastguard WorkerThreadLocalImpl::ThreadLocalImpl() : data() { } ~ThreadLocalImpl()28*9880d681SAndroid Build Coastguard WorkerThreadLocalImpl::~ThreadLocalImpl() { } setInstance(const void * d)29*9880d681SAndroid Build Coastguard Workervoid ThreadLocalImpl::setInstance(const void* d) { 30*9880d681SAndroid Build Coastguard Worker static_assert(sizeof(d) <= sizeof(data), "size too big"); 31*9880d681SAndroid Build Coastguard Worker void **pd = reinterpret_cast<void**>(&data); 32*9880d681SAndroid Build Coastguard Worker *pd = const_cast<void*>(d); 33*9880d681SAndroid Build Coastguard Worker } getInstance()34*9880d681SAndroid Build Coastguard Workervoid *ThreadLocalImpl::getInstance() { 35*9880d681SAndroid Build Coastguard Worker void **pd = reinterpret_cast<void**>(&data); 36*9880d681SAndroid Build Coastguard Worker return *pd; 37*9880d681SAndroid Build Coastguard Worker } removeInstance()38*9880d681SAndroid Build Coastguard Workervoid ThreadLocalImpl::removeInstance() { 39*9880d681SAndroid Build Coastguard Worker setInstance(nullptr); 40*9880d681SAndroid Build Coastguard Worker } 41*9880d681SAndroid Build Coastguard Worker } 42*9880d681SAndroid Build Coastguard Worker #elif defined(LLVM_ON_UNIX) 43*9880d681SAndroid Build Coastguard Worker #include "Unix/ThreadLocal.inc" 44*9880d681SAndroid Build Coastguard Worker #elif defined( LLVM_ON_WIN32) 45*9880d681SAndroid Build Coastguard Worker #include "Windows/ThreadLocal.inc" 46*9880d681SAndroid Build Coastguard Worker #else 47*9880d681SAndroid Build Coastguard Worker #warning Neither LLVM_ON_UNIX nor LLVM_ON_WIN32 set in Support/ThreadLocal.cpp 48*9880d681SAndroid Build Coastguard Worker #endif 49