Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.1 KiB

  1. //===- llvm/Support/ThreadLocal.h - 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 declares the llvm::sys::ThreadLocal class.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_SUPPORT_THREADLOCAL_H
  14. #define LLVM_SUPPORT_THREADLOCAL_H
  15. #include "llvm/Support/DataTypes.h"
  16. #include "llvm/Support/Threading.h"
  17. #include <cassert>
  18. namespace llvm {
  19. namespace sys {
  20. // ThreadLocalImpl - Common base class of all ThreadLocal instantiations.
  21. // YOU SHOULD NEVER USE THIS DIRECTLY.
  22. class ThreadLocalImpl {
  23. typedef uint64_t ThreadLocalDataTy;
  24. /// \brief Platform-specific thread local data.
  25. ///
  26. /// This is embedded in the class and we avoid malloc'ing/free'ing it,
  27. /// to make this class more safe for use along with CrashRecoveryContext.
  28. union {
  29. char data[sizeof(ThreadLocalDataTy)];
  30. ThreadLocalDataTy align_data;
  31. };
  32. public:
  33. ThreadLocalImpl();
  34. virtual ~ThreadLocalImpl();
  35. void setInstance(const void* d);
  36. const void* getInstance();
  37. void removeInstance();
  38. };
  39. /// ThreadLocal - A class used to abstract thread-local storage. It holds,
  40. /// for each thread, a pointer a single object of type T.
  41. template<class T>
  42. class ThreadLocal : public ThreadLocalImpl {
  43. public:
  44. ThreadLocal() : ThreadLocalImpl() { }
  45. /// get - Fetches a pointer to the object associated with the current
  46. /// thread. If no object has yet been associated, it returns NULL;
  47. T* get() { return static_cast<T*>(getInstance()); }
  48. // set - Associates a pointer to an object with the current thread.
  49. void set(T* d) { setInstance(d); }
  50. // erase - Removes the pointer associated with the current thread.
  51. void erase() { removeInstance(); }
  52. };
  53. }
  54. }
  55. #endif