1 //===- ThreadLocal.cpp - Thread Local Data ----------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file implements the llvm::sys::ThreadLocal class.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/Support/ThreadLocal.h"
14 #include "llvm/Config/llvm-config.h"
15 #include "llvm/Support/Compiler.h"
17 //===----------------------------------------------------------------------===//
18 //=== WARNING: Implementation here must contain only TRULY operating system
19 //=== independent code.
20 //===----------------------------------------------------------------------===//
22 #if !defined(LLVM_ENABLE_THREADS) || LLVM_ENABLE_THREADS == 0
23 // Define all methods as no-ops if threading is explicitly disabled
26 ThreadLocalImpl::ThreadLocalImpl() : data() { }
27 ThreadLocalImpl::~ThreadLocalImpl() { }
28 void ThreadLocalImpl::setInstance(const void* d
) {
29 static_assert(sizeof(d
) <= sizeof(data
), "size too big");
30 void **pd
= reinterpret_cast<void**>(&data
);
31 *pd
= const_cast<void*>(d
);
33 void *ThreadLocalImpl::getInstance() {
34 void **pd
= reinterpret_cast<void**>(&data
);
37 void ThreadLocalImpl::removeInstance() {
41 #elif defined(LLVM_ON_UNIX)
42 #include "Unix/ThreadLocal.inc"
43 #elif defined( _WIN32)
44 #include "Windows/ThreadLocal.inc"
46 #warning Neither LLVM_ON_UNIX nor _WIN32 set in Support/ThreadLocal.cpp