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