LLVM API Documentation

Win32/ThreadLocal.inc

Go to the documentation of this file.
00001 //= llvm/System/Win32/ThreadLocal.inc - Win32 Thread Local Data -*- C++ -*-===//
00002 // 
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 // 
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file implements the Win32 specific (non-pthread) ThreadLocal class.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 //===----------------------------------------------------------------------===//
00015 //=== WARNING: Implementation here must contain only generic Win32 code that
00016 //===          is guaranteed to work on *all* Win32 variants.
00017 //===----------------------------------------------------------------------===//
00018 
00019 #include "Win32.h"
00020 #include "llvm/System/ThreadLocal.h"
00021 
00022 namespace llvm {
00023 using namespace sys;
00024 
00025 ThreadLocalImpl::ThreadLocalImpl() {
00026   DWORD* tls = new DWORD;
00027   *tls = TlsAlloc();
00028   assert(*tls != TLS_OUT_OF_INDEXES);
00029   data = tls;
00030 }
00031 
00032 ThreadLocalImpl::~ThreadLocalImpl() {
00033   DWORD* tls = static_cast<DWORD*>(data);
00034   TlsFree(*tls);
00035   delete tls;
00036 }
00037 
00038 const void* ThreadLocalImpl::getInstance() {
00039   DWORD* tls = static_cast<DWORD*>(data);
00040   return TlsGetValue(*tls);
00041 }
00042 
00043 void ThreadLocalImpl::setInstance(const void* d){
00044   DWORD* tls = static_cast<DWORD*>(data);
00045   int errorcode = TlsSetValue(*tls, const_cast<void*>(d));
00046   assert(errorcode != 0);
00047 }
00048 
00049 }