Mutex.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #include "il2cpp-config.h"
  2. #include "os/Mutex.h"
  3. #if IL2CPP_SUPPORT_THREADS
  4. #include "os/Atomic.h"
  5. #if IL2CPP_THREADS_WIN32
  6. #include "os/Win32/MutexImpl.h"
  7. #elif IL2CPP_TARGET_PSP2
  8. #include "os/PSP2/MutexImpl.h"
  9. #elif IL2CPP_THREADS_PTHREAD
  10. #include "os/Posix/MutexImpl.h"
  11. #else
  12. #include "os/MutexImpl.h"
  13. #endif
  14. namespace il2cpp
  15. {
  16. namespace os
  17. {
  18. Mutex::Mutex(bool initiallyOwned)
  19. : m_Mutex(new MutexImpl())
  20. {
  21. if (initiallyOwned)
  22. Lock();
  23. }
  24. Mutex::~Mutex()
  25. {
  26. delete m_Mutex;
  27. }
  28. void Mutex::Lock(bool interruptible)
  29. {
  30. m_Mutex->Lock(interruptible);
  31. }
  32. bool Mutex::TryLock(uint32_t milliseconds, bool interruptible)
  33. {
  34. return m_Mutex->TryLock(milliseconds, interruptible);
  35. }
  36. void Mutex::Unlock()
  37. {
  38. m_Mutex->Unlock();
  39. }
  40. void* Mutex::GetOSHandle()
  41. {
  42. return m_Mutex->GetOSHandle();
  43. }
  44. FastMutex::FastMutex()
  45. : m_Impl(new FastMutexImpl())
  46. {
  47. }
  48. FastMutex::~FastMutex()
  49. {
  50. delete m_Impl;
  51. }
  52. void FastMutex::Lock()
  53. {
  54. m_Impl->Lock();
  55. }
  56. void FastMutex::Unlock()
  57. {
  58. m_Impl->Unlock();
  59. }
  60. FastMutexImpl* FastMutex::GetImpl()
  61. {
  62. return m_Impl;
  63. }
  64. }
  65. }
  66. #else
  67. namespace il2cpp
  68. {
  69. namespace os
  70. {
  71. Mutex::Mutex(bool initiallyOwned)
  72. {
  73. }
  74. Mutex::~Mutex()
  75. {
  76. }
  77. void Mutex::Lock(bool interruptible)
  78. {
  79. }
  80. bool Mutex::TryLock(uint32_t milliseconds, bool interruptible)
  81. {
  82. return true;
  83. }
  84. void Mutex::Unlock()
  85. {
  86. }
  87. void* Mutex::GetOSHandle()
  88. {
  89. return NULL;
  90. }
  91. FastMutex::FastMutex()
  92. {
  93. }
  94. FastMutex::~FastMutex()
  95. {
  96. }
  97. void FastMutex::Lock()
  98. {
  99. }
  100. void FastMutex::Unlock()
  101. {
  102. }
  103. FastMutexImpl* FastMutex::GetImpl()
  104. {
  105. IL2CPP_ASSERT(0 && "Threads are not enabled for this platform.");
  106. return NULL;
  107. }
  108. }
  109. }
  110. #endif