ThreadLocalValue.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #pragma once
  2. #include "os/ErrorCodes.h"
  3. #if IL2CPP_SUPPORT_THREADS || IL2CPP_TINY
  4. #if IL2CPP_THREADS_WIN32
  5. #include "os/Win32/ThreadLocalValueImpl.h"
  6. #elif IL2CPP_THREADS_PTHREAD
  7. #include "os/Posix/ThreadLocalValueImpl.h"
  8. #else
  9. #include "os/ThreadLocalValueImpl.h"
  10. #endif
  11. #endif
  12. namespace il2cpp
  13. {
  14. namespace os
  15. {
  16. class ThreadLocalValueImpl;
  17. class ThreadLocalValue
  18. {
  19. #if IL2CPP_SUPPORT_THREADS || IL2CPP_TINY
  20. public:
  21. inline ThreadLocalValue()
  22. : m_ThreadLocalValue(new ThreadLocalValueImpl())
  23. {
  24. }
  25. inline ~ThreadLocalValue()
  26. {
  27. delete m_ThreadLocalValue;
  28. }
  29. inline ErrorCode SetValue(void* value)
  30. {
  31. return m_ThreadLocalValue->SetValue(value);
  32. }
  33. inline ErrorCode GetValue(void** value)
  34. {
  35. return m_ThreadLocalValue->GetValue(value);
  36. }
  37. private:
  38. ThreadLocalValueImpl * m_ThreadLocalValue;
  39. #else
  40. public:
  41. inline ThreadLocalValue()
  42. {
  43. }
  44. inline ~ThreadLocalValue()
  45. {
  46. }
  47. inline ErrorCode SetValue(void* value)
  48. {
  49. m_ThreadLocalValue = value;
  50. return kErrorCodeSuccess;
  51. }
  52. inline ErrorCode GetValue(void** value)
  53. {
  54. *value = m_ThreadLocalValue;
  55. return kErrorCodeSuccess;
  56. }
  57. private:
  58. void* m_ThreadLocalValue;
  59. #endif
  60. };
  61. }
  62. }