]>
Commit | Line | Data |
---|---|---|
223e47cc LB |
1 | //===- ThreadLocal.cpp - Thread Local Data ----------------------*- 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 | // This file implements the llvm::sys::ThreadLocal class. | |
11 | // | |
12 | //===----------------------------------------------------------------------===// | |
13 | ||
14 | #include "llvm/Config/config.h" | |
1a4d82fc | 15 | #include "llvm/Support/Compiler.h" |
223e47cc LB |
16 | #include "llvm/Support/ThreadLocal.h" |
17 | ||
18 | //===----------------------------------------------------------------------===// | |
19 | //=== WARNING: Implementation here must contain only TRULY operating system | |
20 | //=== independent code. | |
21 | //===----------------------------------------------------------------------===// | |
22 | ||
23 | #if !defined(LLVM_ENABLE_THREADS) || LLVM_ENABLE_THREADS == 0 | |
24 | // Define all methods as no-ops if threading is explicitly disabled | |
25 | namespace llvm { | |
26 | using namespace sys; | |
1a4d82fc | 27 | ThreadLocalImpl::ThreadLocalImpl() : data() { } |
223e47cc LB |
28 | ThreadLocalImpl::~ThreadLocalImpl() { } |
29 | void ThreadLocalImpl::setInstance(const void* d) { | |
1a4d82fc | 30 | static_assert(sizeof(d) <= sizeof(data), "size too big"); |
223e47cc LB |
31 | void **pd = reinterpret_cast<void**>(&data); |
32 | *pd = const_cast<void*>(d); | |
33 | } | |
85aaf69f | 34 | void *ThreadLocalImpl::getInstance() { |
223e47cc LB |
35 | void **pd = reinterpret_cast<void**>(&data); |
36 | return *pd; | |
37 | } | |
223e47cc | 38 | void ThreadLocalImpl::removeInstance() { |
1a4d82fc | 39 | setInstance(nullptr); |
223e47cc | 40 | } |
223e47cc | 41 | } |
223e47cc LB |
42 | #elif defined(LLVM_ON_UNIX) |
43 | #include "Unix/ThreadLocal.inc" | |
44 | #elif defined( LLVM_ON_WIN32) | |
45 | #include "Windows/ThreadLocal.inc" | |
46 | #else | |
47 | #warning Neither LLVM_ON_UNIX nor LLVM_ON_WIN32 set in Support/ThreadLocal.cpp | |
48 | #endif |