LLVM  9.0.0svn
ThreadLocal.cpp
Go to the documentation of this file.
1 //===- ThreadLocal.cpp - Thread Local Data ----------------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the llvm::sys::ThreadLocal class.
10 //
11 //===----------------------------------------------------------------------===//
12 
14 #include "llvm/Config/llvm-config.h"
15 #include "llvm/Support/Compiler.h"
16 
17 //===----------------------------------------------------------------------===//
18 //=== WARNING: Implementation here must contain only TRULY operating system
19 //=== independent code.
20 //===----------------------------------------------------------------------===//
21 
22 #if !defined(LLVM_ENABLE_THREADS) || LLVM_ENABLE_THREADS == 0
23 // Define all methods as no-ops if threading is explicitly disabled
24 namespace llvm {
25 using namespace sys;
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);
32 }
34  void **pd = reinterpret_cast<void**>(&data);
35  return *pd;
36 }
38  setInstance(nullptr);
39 }
40 }
41 #elif defined(LLVM_ON_UNIX)
42 #include "Unix/ThreadLocal.inc"
43 #elif defined( _WIN32)
44 #include "Windows/ThreadLocal.inc"
45 #else
46 #warning Neither LLVM_ON_UNIX nor _WIN32 set in Support/ThreadLocal.cpp
47 #endif
This class represents lattice values for constants.
Definition: AllocatorList.h:23
char data[sizeof(ThreadLocalDataTy)]
Definition: ThreadLocal.h:31
void setInstance(const void *d)