diff --git a/include/llvm/System/ThreadLocal.h b/include/llvm/System/ThreadLocal.h index 3d44f62e959..e6edd79d6ff 100644 --- a/include/llvm/System/ThreadLocal.h +++ b/include/llvm/System/ThreadLocal.h @@ -28,6 +28,7 @@ namespace llvm { virtual ~ThreadLocalImpl(); void setInstance(const void* d); const void* getInstance(); + void removeInstance(); }; /// ThreadLocal - A class used to abstract thread-local storage. It holds, @@ -43,6 +44,9 @@ namespace llvm { // set - Associates a pointer to an object with the current thread. void set(T* d) { setInstance(d); } + + // erase - Removes the pointer associated with the current thread. + void erase() { removeInstance(); } }; } } diff --git a/lib/System/ThreadLocal.cpp b/lib/System/ThreadLocal.cpp index e7054b52814..b84a8e7fd6f 100644 --- a/lib/System/ThreadLocal.cpp +++ b/lib/System/ThreadLocal.cpp @@ -67,6 +67,10 @@ const void* ThreadLocalImpl::getInstance() { return pthread_getspecific(*key); } +void ThreadLocalImpl::removeInstance() { + setInstance(0); +} + } #elif defined(LLVM_ON_UNIX) diff --git a/lib/System/Unix/ThreadLocal.inc b/lib/System/Unix/ThreadLocal.inc index 83d554d3077..6769520a6fb 100644 --- a/lib/System/Unix/ThreadLocal.inc +++ b/lib/System/Unix/ThreadLocal.inc @@ -22,4 +22,5 @@ ThreadLocalImpl::ThreadLocalImpl() { } ThreadLocalImpl::~ThreadLocalImpl() { } void ThreadLocalImpl::setInstance(const void* d) { data = const_cast(d);} const void* ThreadLocalImpl::getInstance() { return data; } +void ThreadLocalImpl::removeInstance() { setInstance(0); } } diff --git a/lib/System/Win32/ThreadLocal.inc b/lib/System/Win32/ThreadLocal.inc index c8f7840b003..b8b933c4d29 100644 --- a/lib/System/Win32/ThreadLocal.inc +++ b/lib/System/Win32/ThreadLocal.inc @@ -46,4 +46,8 @@ void ThreadLocalImpl::setInstance(const void* d){ assert(errorcode != 0); } +void ThreadLocalImpl::removeInstance() { + setInstance(0); +} + }