Mercurial > hg > CbC > CbC_llvm
comparison lib/Support/ThreadLocal.cpp @ 77:54457678186b LLVM3.6
LLVM 3.6
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 08 Sep 2014 22:06:00 +0900 |
parents | 95c75e76d11b |
children | 60c9769439b8 |
comparison
equal
deleted
inserted
replaced
34:e874dbf0ad9d | 77:54457678186b |
---|---|
10 // This file implements the llvm::sys::ThreadLocal class. | 10 // This file implements the llvm::sys::ThreadLocal class. |
11 // | 11 // |
12 //===----------------------------------------------------------------------===// | 12 //===----------------------------------------------------------------------===// |
13 | 13 |
14 #include "llvm/Config/config.h" | 14 #include "llvm/Config/config.h" |
15 #include "llvm/Support/Compiler.h" | |
15 #include "llvm/Support/ThreadLocal.h" | 16 #include "llvm/Support/ThreadLocal.h" |
16 | 17 |
17 //===----------------------------------------------------------------------===// | 18 //===----------------------------------------------------------------------===// |
18 //=== WARNING: Implementation here must contain only TRULY operating system | 19 //=== WARNING: Implementation here must contain only TRULY operating system |
19 //=== independent code. | 20 //=== independent code. |
21 | 22 |
22 #if !defined(LLVM_ENABLE_THREADS) || LLVM_ENABLE_THREADS == 0 | 23 #if !defined(LLVM_ENABLE_THREADS) || LLVM_ENABLE_THREADS == 0 |
23 // Define all methods as no-ops if threading is explicitly disabled | 24 // Define all methods as no-ops if threading is explicitly disabled |
24 namespace llvm { | 25 namespace llvm { |
25 using namespace sys; | 26 using namespace sys; |
26 ThreadLocalImpl::ThreadLocalImpl() { } | 27 ThreadLocalImpl::ThreadLocalImpl() : data() { } |
27 ThreadLocalImpl::~ThreadLocalImpl() { } | 28 ThreadLocalImpl::~ThreadLocalImpl() { } |
28 void ThreadLocalImpl::setInstance(const void* d) { | 29 void ThreadLocalImpl::setInstance(const void* d) { |
29 typedef int SIZE_TOO_BIG[sizeof(d) <= sizeof(data) ? 1 : -1]; | 30 static_assert(sizeof(d) <= sizeof(data), "size too big"); |
30 void **pd = reinterpret_cast<void**>(&data); | 31 void **pd = reinterpret_cast<void**>(&data); |
31 *pd = const_cast<void*>(d); | 32 *pd = const_cast<void*>(d); |
32 } | 33 } |
33 const void* ThreadLocalImpl::getInstance() { | 34 const void* ThreadLocalImpl::getInstance() { |
34 void **pd = reinterpret_cast<void**>(&data); | 35 void **pd = reinterpret_cast<void**>(&data); |
48 | 49 |
49 namespace llvm { | 50 namespace llvm { |
50 using namespace sys; | 51 using namespace sys; |
51 | 52 |
52 ThreadLocalImpl::ThreadLocalImpl() : data() { | 53 ThreadLocalImpl::ThreadLocalImpl() : data() { |
53 typedef int SIZE_TOO_BIG[sizeof(pthread_key_t) <= sizeof(data) ? 1 : -1]; | 54 static_assert(sizeof(pthread_key_t) <= sizeof(data), "size too big"); |
54 pthread_key_t* key = reinterpret_cast<pthread_key_t*>(&data); | 55 pthread_key_t* key = reinterpret_cast<pthread_key_t*>(&data); |
55 int errorcode = pthread_key_create(key, NULL); | 56 int errorcode = pthread_key_create(key, nullptr); |
56 assert(errorcode == 0); | 57 assert(errorcode == 0); |
57 (void) errorcode; | 58 (void) errorcode; |
58 } | 59 } |
59 | 60 |
60 ThreadLocalImpl::~ThreadLocalImpl() { | 61 ThreadLocalImpl::~ThreadLocalImpl() { |
75 pthread_key_t* key = reinterpret_cast<pthread_key_t*>(&data); | 76 pthread_key_t* key = reinterpret_cast<pthread_key_t*>(&data); |
76 return pthread_getspecific(*key); | 77 return pthread_getspecific(*key); |
77 } | 78 } |
78 | 79 |
79 void ThreadLocalImpl::removeInstance() { | 80 void ThreadLocalImpl::removeInstance() { |
80 setInstance(0); | 81 setInstance(nullptr); |
81 } | 82 } |
82 | 83 |
83 } | 84 } |
84 | 85 |
85 #elif defined(LLVM_ON_UNIX) | 86 #elif defined(LLVM_ON_UNIX) |