1 //= llvm/Support/Win32/ThreadLocal.inc - Win32 Thread Local Data -*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the Win32 specific (non-pthread) ThreadLocal class.
12 //===----------------------------------------------------------------------===//
14 //===----------------------------------------------------------------------===//
15 //=== WARNING: Implementation here must contain only generic Win32 code that
16 //=== is guaranteed to work on *all* Win32 variants.
17 //===----------------------------------------------------------------------===//
19 #include "WindowsSupport.h"
20 #include "llvm/Support/ThreadLocal.h"
25 ThreadLocalImpl::ThreadLocalImpl() : data() {
26 typedef int SIZE_TOO_BIG[sizeof(DWORD) <= sizeof(data) ? 1 : -1];
27 DWORD* tls = reinterpret_cast<DWORD*>(&data);
29 assert(*tls != TLS_OUT_OF_INDEXES);
32 ThreadLocalImpl::~ThreadLocalImpl() {
33 DWORD* tls = reinterpret_cast<DWORD*>(&data);
37 const void* ThreadLocalImpl::getInstance() {
38 DWORD* tls = reinterpret_cast<DWORD*>(&data);
39 return TlsGetValue(*tls);
42 void ThreadLocalImpl::setInstance(const void* d){
43 DWORD* tls = reinterpret_cast<DWORD*>(&data);
44 int errorcode = TlsSetValue(*tls, const_cast<void*>(d));
45 assert(errorcode != 0);
49 void ThreadLocalImpl::removeInstance() {