Monitor.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #pragma once
  2. #include "il2cpp-config.h"
  3. struct Il2CppObject;
  4. namespace il2cpp
  5. {
  6. namespace vm
  7. {
  8. class LIBIL2CPP_CODEGEN_API Monitor
  9. {
  10. public:
  11. static void Enter(Il2CppObject* object);
  12. static bool TryEnter(Il2CppObject* object, uint32_t timeout);
  13. static void Exit(Il2CppObject* object);
  14. static void Pulse(Il2CppObject* object);
  15. static void PulseAll(Il2CppObject* object);
  16. static void Wait(Il2CppObject* object);
  17. static bool TryWait(Il2CppObject* object, uint32_t timeout);
  18. static bool IsAcquired(Il2CppObject* object);
  19. static bool IsOwnedByCurrentThread(Il2CppObject* object);
  20. };
  21. #if !IL2CPP_SUPPORT_THREADS
  22. inline void Monitor::Enter(Il2CppObject* object)
  23. {
  24. }
  25. inline bool Monitor::TryEnter(Il2CppObject* object, uint32_t timeout)
  26. {
  27. return true;
  28. }
  29. inline void Monitor::Exit(Il2CppObject* object)
  30. {
  31. }
  32. inline void Monitor::Pulse(Il2CppObject* object)
  33. {
  34. }
  35. inline void Monitor::PulseAll(Il2CppObject* object)
  36. {
  37. }
  38. inline void Monitor::Wait(Il2CppObject* object)
  39. {
  40. }
  41. inline bool Monitor::TryWait(Il2CppObject* object, uint32_t timeout)
  42. {
  43. return true;
  44. }
  45. inline bool Monitor::IsAcquired(Il2CppObject* object)
  46. {
  47. return true;
  48. }
  49. inline bool Monitor::IsOwnedByCurrentThread(Il2CppObject* object)
  50. {
  51. return true;
  52. }
  53. #endif
  54. struct MonitorHolder
  55. {
  56. MonitorHolder(Il2CppObject* obj) :
  57. m_Object(obj)
  58. {
  59. Monitor::Enter(obj);
  60. }
  61. ~MonitorHolder()
  62. {
  63. Monitor::Exit(m_Object);
  64. }
  65. private:
  66. Il2CppObject* m_Object;
  67. };
  68. } /* namespace vm */
  69. } /* namespace il2cpp */