2
0

ThreadLocal.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. //===- ThreadLocal.cpp - Thread Local Data ----------------------*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file implements the llvm::sys::ThreadLocal class.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "llvm/Config/config.h"
  14. #include "llvm/Support/Compiler.h"
  15. #include "llvm/Support/ThreadLocal.h"
  16. //===----------------------------------------------------------------------===//
  17. //=== WARNING: Implementation here must contain only TRULY operating system
  18. //=== independent code.
  19. //===----------------------------------------------------------------------===//
  20. #if !defined(LLVM_ENABLE_THREADS) || LLVM_ENABLE_THREADS == 0
  21. // Define all methods as no-ops if threading is explicitly disabled
  22. namespace llvm {
  23. using namespace sys;
  24. ThreadLocalImpl::ThreadLocalImpl() : data() { }
  25. ThreadLocalImpl::~ThreadLocalImpl() { }
  26. void ThreadLocalImpl::setInstance(const void* d) {
  27. static_assert(sizeof(d) <= sizeof(data), "size too big");
  28. void **pd = reinterpret_cast<void**>(&data);
  29. *pd = const_cast<void*>(d);
  30. }
  31. void *ThreadLocalImpl::getInstance() {
  32. void **pd = reinterpret_cast<void**>(&data);
  33. return *pd;
  34. }
  35. void ThreadLocalImpl::removeInstance() {
  36. setInstance(nullptr);
  37. }
  38. }
  39. #elif defined(LLVM_ON_UNIX)
  40. #include "Unix/ThreadLocal.inc"
  41. #elif defined( LLVM_ON_WIN32)
  42. #include "Windows/ThreadLocal.inc"
  43. #else
  44. #warning Neither LLVM_ON_UNIX nor LLVM_ON_WIN32 set in Support/ThreadLocal.cpp
  45. #endif