diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2012-06-12 00:21:31 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2012-06-12 00:21:31 +0000 |
commit | 793537d21f8aa46458a5733d96816ba8bddeef50 (patch) | |
tree | 441f269114a3f3b693c2f8fb15ad7fef979f2562 /lib/Support/ThreadLocal.cpp | |
parent | 0eb3a3524e9d68642e574780d19c781386ed4469 (diff) |
For llvm::sys::ThreadLocalImpl instead of malloc'ing the platform-specific
thread local data, embed them in the class using a uint64_t and make sure
we get compiler errors if there's a platform where this is not big enough.
This makes ThreadLocal more safe for using it in conjunction with CrashRecoveryContext.
Related to crash in rdar://11434201.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158342 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/ThreadLocal.cpp')
-rw-r--r-- | lib/Support/ThreadLocal.cpp | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/lib/Support/ThreadLocal.cpp b/lib/Support/ThreadLocal.cpp index 08b12b658b..1030a2b97d 100644 --- a/lib/Support/ThreadLocal.cpp +++ b/lib/Support/ThreadLocal.cpp @@ -41,30 +41,29 @@ namespace llvm { using namespace sys; ThreadLocalImpl::ThreadLocalImpl() : data(0) { - pthread_key_t* key = new pthread_key_t; + typedef int SIZE_TOO_BIG[sizeof(pthread_key_t) <= sizeof(data) ? 1 : -1]; + pthread_key_t* key = reinterpret_cast<pthread_key_t*>(&data); int errorcode = pthread_key_create(key, NULL); assert(errorcode == 0); (void) errorcode; - data = (void*)key; } ThreadLocalImpl::~ThreadLocalImpl() { - pthread_key_t* key = static_cast<pthread_key_t*>(data); + pthread_key_t* key = reinterpret_cast<pthread_key_t*>(&data); int errorcode = pthread_key_delete(*key); assert(errorcode == 0); (void) errorcode; - delete key; } void ThreadLocalImpl::setInstance(const void* d) { - pthread_key_t* key = static_cast<pthread_key_t*>(data); + pthread_key_t* key = reinterpret_cast<pthread_key_t*>(&data); int errorcode = pthread_setspecific(*key, d); assert(errorcode == 0); (void) errorcode; } const void* ThreadLocalImpl::getInstance() { - pthread_key_t* key = static_cast<pthread_key_t*>(data); + pthread_key_t* key = reinterpret_cast<pthread_key_t*>(&data); return pthread_getspecific(*key); } |