2009-06-26 05:58:01 +08:00
|
|
|
//===- ThreadLocal.cpp - Thread Local Data ----------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the llvm::sys::ThreadLocal class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-06-06 19:49:48 +08:00
|
|
|
#include "llvm/Support/ThreadLocal.h"
|
2018-04-30 22:59:11 +08:00
|
|
|
#include "llvm/Config/llvm-config.h"
|
2013-12-31 11:16:55 +08:00
|
|
|
#include "llvm/Support/Compiler.h"
|
2009-06-26 05:58:01 +08:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//=== WARNING: Implementation here must contain only TRULY operating system
|
|
|
|
//=== independent code.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-11-28 08:48:58 +08:00
|
|
|
#if !defined(LLVM_ENABLE_THREADS) || LLVM_ENABLE_THREADS == 0
|
2009-06-26 05:58:01 +08:00
|
|
|
// Define all methods as no-ops if threading is explicitly disabled
|
|
|
|
namespace llvm {
|
|
|
|
using namespace sys;
|
2013-12-20 04:32:44 +08:00
|
|
|
ThreadLocalImpl::ThreadLocalImpl() : data() { }
|
2009-06-26 05:58:01 +08:00
|
|
|
ThreadLocalImpl::~ThreadLocalImpl() { }
|
2012-06-14 00:30:06 +08:00
|
|
|
void ThreadLocalImpl::setInstance(const void* d) {
|
2014-03-02 21:10:45 +08:00
|
|
|
static_assert(sizeof(d) <= sizeof(data), "size too big");
|
2012-06-14 00:30:06 +08:00
|
|
|
void **pd = reinterpret_cast<void**>(&data);
|
|
|
|
*pd = const_cast<void*>(d);
|
|
|
|
}
|
2014-12-15 09:04:45 +08:00
|
|
|
void *ThreadLocalImpl::getInstance() {
|
2012-06-14 00:30:06 +08:00
|
|
|
void **pd = reinterpret_cast<void**>(&data);
|
2012-06-27 01:13:58 +08:00
|
|
|
return *pd;
|
|
|
|
}
|
2010-07-29 06:49:43 +08:00
|
|
|
void ThreadLocalImpl::removeInstance() {
|
2014-04-07 12:17:22 +08:00
|
|
|
setInstance(nullptr);
|
2010-07-29 06:49:43 +08:00
|
|
|
}
|
2009-06-26 05:58:01 +08:00
|
|
|
}
|
|
|
|
#elif defined(LLVM_ON_UNIX)
|
|
|
|
#include "Unix/ThreadLocal.inc"
|
2018-04-29 08:45:03 +08:00
|
|
|
#elif defined( _WIN32)
|
2010-11-30 02:16:10 +08:00
|
|
|
#include "Windows/ThreadLocal.inc"
|
2009-06-26 05:58:01 +08:00
|
|
|
#else
|
2018-04-29 08:45:03 +08:00
|
|
|
#warning Neither LLVM_ON_UNIX nor _WIN32 set in Support/ThreadLocal.cpp
|
2009-06-26 05:58:01 +08:00
|
|
|
#endif
|