mirror of
https://github.com/RPCS3/llvm.git
synced 2025-05-19 03:45:53 +00:00

to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351636 91177308-0d34-0410-b5e6-96231b3b80d8
52 lines
1.6 KiB
C++
52 lines
1.6 KiB
C++
//= llvm/Support/Win32/ThreadLocal.inc - Win32 Thread Local Data -*- C++ -*-===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file implements the Win32 specific (non-pthread) ThreadLocal class.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
//=== WARNING: Implementation here must contain only generic Win32 code that
|
|
//=== is guaranteed to work on *all* Win32 variants.
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "WindowsSupport.h"
|
|
#include "llvm/Support/ThreadLocal.h"
|
|
|
|
namespace llvm {
|
|
|
|
sys::ThreadLocalImpl::ThreadLocalImpl() : data() {
|
|
static_assert(sizeof(DWORD) <= sizeof(data), "size too big");
|
|
DWORD* tls = reinterpret_cast<DWORD*>(&data);
|
|
*tls = TlsAlloc();
|
|
assert(*tls != TLS_OUT_OF_INDEXES);
|
|
}
|
|
|
|
sys::ThreadLocalImpl::~ThreadLocalImpl() {
|
|
DWORD* tls = reinterpret_cast<DWORD*>(&data);
|
|
TlsFree(*tls);
|
|
}
|
|
|
|
void *sys::ThreadLocalImpl::getInstance() {
|
|
DWORD* tls = reinterpret_cast<DWORD*>(&data);
|
|
return TlsGetValue(*tls);
|
|
}
|
|
|
|
void sys::ThreadLocalImpl::setInstance(const void* d){
|
|
DWORD* tls = reinterpret_cast<DWORD*>(&data);
|
|
int errorcode = TlsSetValue(*tls, const_cast<void*>(d));
|
|
assert(errorcode != 0);
|
|
(void)errorcode;
|
|
}
|
|
|
|
void sys::ThreadLocalImpl::removeInstance() {
|
|
setInstance(0);
|
|
}
|
|
|
|
}
|