mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-03-03 14:31:10 +00:00
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
This commit is contained in:
parent
0eb3a3524e
commit
793537d21f
@ -15,6 +15,7 @@
|
|||||||
#define LLVM_SYSTEM_THREAD_LOCAL_H
|
#define LLVM_SYSTEM_THREAD_LOCAL_H
|
||||||
|
|
||||||
#include "llvm/Support/Threading.h"
|
#include "llvm/Support/Threading.h"
|
||||||
|
#include "llvm/Support/DataTypes.h"
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
@ -22,7 +23,12 @@ namespace llvm {
|
|||||||
// ThreadLocalImpl - Common base class of all ThreadLocal instantiations.
|
// ThreadLocalImpl - Common base class of all ThreadLocal instantiations.
|
||||||
// YOU SHOULD NEVER USE THIS DIRECTLY.
|
// YOU SHOULD NEVER USE THIS DIRECTLY.
|
||||||
class ThreadLocalImpl {
|
class ThreadLocalImpl {
|
||||||
void* data;
|
typedef uint64_t ThreadLocalDataTy;
|
||||||
|
/// \brief Platform-specific thread local data.
|
||||||
|
///
|
||||||
|
/// This is embedded in the class and we avoid malloc'ing/free'ing it,
|
||||||
|
/// to make this class more safe for use along with CrashRecoveryContext.
|
||||||
|
ThreadLocalDataTy data;
|
||||||
public:
|
public:
|
||||||
ThreadLocalImpl();
|
ThreadLocalImpl();
|
||||||
virtual ~ThreadLocalImpl();
|
virtual ~ThreadLocalImpl();
|
||||||
|
@ -41,30 +41,29 @@ namespace llvm {
|
|||||||
using namespace sys;
|
using namespace sys;
|
||||||
|
|
||||||
ThreadLocalImpl::ThreadLocalImpl() : data(0) {
|
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);
|
int errorcode = pthread_key_create(key, NULL);
|
||||||
assert(errorcode == 0);
|
assert(errorcode == 0);
|
||||||
(void) errorcode;
|
(void) errorcode;
|
||||||
data = (void*)key;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ThreadLocalImpl::~ThreadLocalImpl() {
|
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);
|
int errorcode = pthread_key_delete(*key);
|
||||||
assert(errorcode == 0);
|
assert(errorcode == 0);
|
||||||
(void) errorcode;
|
(void) errorcode;
|
||||||
delete key;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThreadLocalImpl::setInstance(const void* d) {
|
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);
|
int errorcode = pthread_setspecific(*key, d);
|
||||||
assert(errorcode == 0);
|
assert(errorcode == 0);
|
||||||
(void) errorcode;
|
(void) errorcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
const void* ThreadLocalImpl::getInstance() {
|
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);
|
return pthread_getspecific(*key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,26 +22,25 @@
|
|||||||
namespace llvm {
|
namespace llvm {
|
||||||
using namespace sys;
|
using namespace sys;
|
||||||
|
|
||||||
ThreadLocalImpl::ThreadLocalImpl() {
|
ThreadLocalImpl::ThreadLocalImpl() : data(0) {
|
||||||
DWORD* tls = new DWORD;
|
typedef int SIZE_TOO_BIG[sizeof(DWORD) <= sizeof(data) ? 1 : -1];
|
||||||
|
DWORD* tls = reinterpret_cast<DWORD*>(&data);
|
||||||
*tls = TlsAlloc();
|
*tls = TlsAlloc();
|
||||||
assert(*tls != TLS_OUT_OF_INDEXES);
|
assert(*tls != TLS_OUT_OF_INDEXES);
|
||||||
data = tls;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ThreadLocalImpl::~ThreadLocalImpl() {
|
ThreadLocalImpl::~ThreadLocalImpl() {
|
||||||
DWORD* tls = static_cast<DWORD*>(data);
|
DWORD* tls = reinterpret_cast<DWORD*>(&data);
|
||||||
TlsFree(*tls);
|
TlsFree(*tls);
|
||||||
delete tls;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const void* ThreadLocalImpl::getInstance() {
|
const void* ThreadLocalImpl::getInstance() {
|
||||||
DWORD* tls = static_cast<DWORD*>(data);
|
DWORD* tls = reinterpret_cast<DWORD*>(&data);
|
||||||
return TlsGetValue(*tls);
|
return TlsGetValue(*tls);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThreadLocalImpl::setInstance(const void* d){
|
void ThreadLocalImpl::setInstance(const void* d){
|
||||||
DWORD* tls = static_cast<DWORD*>(data);
|
DWORD* tls = reinterpret_cast<DWORD*>(&data);
|
||||||
int errorcode = TlsSetValue(*tls, const_cast<void*>(d));
|
int errorcode = TlsSetValue(*tls, const_cast<void*>(d));
|
||||||
assert(errorcode != 0);
|
assert(errorcode != 0);
|
||||||
(void)errorcode;
|
(void)errorcode;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user