Make Program::Wait differentiate execution failure due to the file
[oota-llvm.git] / lib / System / ThreadLocal.cpp
index 1c0703667095c6c2ff7ee0d036c4c0470934587b..f6a55a1c0b9b183b1fbccc7976e52bf95406abbc 100644 (file)
@@ -25,12 +25,13 @@ namespace llvm {
 using namespace sys;
 ThreadLocalImpl::ThreadLocalImpl() { }
 ThreadLocalImpl::~ThreadLocalImpl() { }
-void ThreadLocalImpl::setInstance(void* d) { data = d; }
-void* ThreadLocalImpl::getInstance() { return data; }
+void ThreadLocalImpl::setInstance(const void* d) { data = const_cast<void*>(d);}
+const void* ThreadLocalImpl::getInstance() { return data; }
+void ThreadLocalImpl::removeInstance() { data = 0; }
 }
 #else
 
-#if defined(HAVE_PTHREAD_H) && defined(HAVE_PTHREAD_MUTEX_LOCK)
+#if defined(HAVE_PTHREAD_H) && defined(HAVE_PTHREAD_GETSPECIFIC)
 
 #include <cassert>
 #include <pthread.h>
@@ -43,27 +44,34 @@ ThreadLocalImpl::ThreadLocalImpl() : data(0) {
   pthread_key_t* key = new pthread_key_t;
   int errorcode = pthread_key_create(key, NULL);
   assert(errorcode == 0);
-  data = key;
+  (void) errorcode;
+  data = (void*)key;
 }
 
 ThreadLocalImpl::~ThreadLocalImpl() {
   pthread_key_t* key = static_cast<pthread_key_t*>(data);
   int errorcode = pthread_key_delete(*key);
-  assert(errorcode = 0);
+  assert(errorcode == 0);
+  (void) errorcode;
   delete key;
 }
 
-void ThreadLocalImpl::setInstance(void* d) {
+void ThreadLocalImpl::setInstance(const void* d) {
   pthread_key_t* key = static_cast<pthread_key_t*>(data);
   int errorcode = pthread_setspecific(*key, d);
   assert(errorcode == 0);
+  (void) errorcode;
 }
 
-void* ThreadLocalImpl::getInstance() {
+const void* ThreadLocalImpl::getInstance() {
   pthread_key_t* key = static_cast<pthread_key_t*>(data);
   return pthread_getspecific(*key);
 }
 
+void ThreadLocalImpl::removeInstance() {
+  setInstance(0);
+}
+
 }
 
 #elif defined(LLVM_ON_UNIX)