2009-06-25 21:58:01 +00: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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/Config/config.h"
|
2013-12-31 03:16:55 +00:00
|
|
|
#include "llvm/Support/Compiler.h"
|
2010-11-29 18:16:10 +00:00
|
|
|
#include "llvm/Support/ThreadLocal.h"
|
2009-06-25 21:58:01 +00:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//=== WARNING: Implementation here must contain only TRULY operating system
|
|
|
|
//=== independent code.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-11-28 00:48:58 +00:00
|
|
|
#if !defined(LLVM_ENABLE_THREADS) || LLVM_ENABLE_THREADS == 0
|
2009-06-25 21:58:01 +00:00
|
|
|
// Define all methods as no-ops if threading is explicitly disabled
|
|
|
|
namespace llvm {
|
|
|
|
using namespace sys;
|
2013-12-19 20:32:44 +00:00
|
|
|
ThreadLocalImpl::ThreadLocalImpl() : data() { }
|
2009-06-25 21:58:01 +00:00
|
|
|
ThreadLocalImpl::~ThreadLocalImpl() { }
|
2012-06-13 16:30:06 +00:00
|
|
|
void ThreadLocalImpl::setInstance(const void* d) {
|
2014-03-02 13:10:45 +00:00
|
|
|
static_assert(sizeof(d) <= sizeof(data), "size too big");
|
2012-06-13 16:30:06 +00:00
|
|
|
void **pd = reinterpret_cast<void**>(&data);
|
|
|
|
*pd = const_cast<void*>(d);
|
|
|
|
}
|
2014-12-15 01:04:45 +00:00
|
|
|
void *ThreadLocalImpl::getInstance() {
|
2012-06-13 16:30:06 +00:00
|
|
|
void **pd = reinterpret_cast<void**>(&data);
|
2012-06-26 17:13:58 +00:00
|
|
|
return *pd;
|
|
|
|
}
|
2010-07-28 22:49:43 +00:00
|
|
|
void ThreadLocalImpl::removeInstance() {
|
2014-04-07 04:17:22 +00:00
|
|
|
setInstance(nullptr);
|
2010-07-28 22:49:43 +00:00
|
|
|
}
|
2009-06-25 21:58:01 +00:00
|
|
|
}
|
|
|
|
#elif defined(LLVM_ON_UNIX)
|
|
|
|
#include "Unix/ThreadLocal.inc"
|
|
|
|
#elif defined( LLVM_ON_WIN32)
|
2010-11-29 18:16:10 +00:00
|
|
|
#include "Windows/ThreadLocal.inc"
|
2009-06-25 21:58:01 +00:00
|
|
|
#else
|
2011-10-11 20:02:52 +00:00
|
|
|
#warning Neither LLVM_ON_UNIX nor LLVM_ON_WIN32 set in Support/ThreadLocal.cpp
|
2009-06-25 21:58:01 +00:00
|
|
|
#endif
|