MutexImpl.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #pragma once
  2. #if IL2CPP_THREADS_WIN32
  3. #include "os/ErrorCodes.h"
  4. #include "os/WaitStatus.h"
  5. #include "utils/NonCopyable.h"
  6. #include "WindowsHeaders.h"
  7. namespace il2cpp
  8. {
  9. namespace os
  10. {
  11. class MutexImpl : public il2cpp::utils::NonCopyable
  12. {
  13. public:
  14. MutexImpl();
  15. ~MutexImpl();
  16. void Lock(bool interruptible);
  17. bool TryLock(uint32_t milliseconds, bool interruptible);
  18. void Unlock();
  19. private:
  20. HANDLE m_MutexHandle;
  21. };
  22. class FastMutexImpl
  23. {
  24. public:
  25. FastMutexImpl()
  26. {
  27. InitializeCriticalSection(&m_CritialSection);
  28. }
  29. ~FastMutexImpl()
  30. {
  31. DeleteCriticalSection(&m_CritialSection);
  32. }
  33. void Lock()
  34. {
  35. EnterCriticalSection(&m_CritialSection);
  36. }
  37. void Unlock()
  38. {
  39. LeaveCriticalSection(&m_CritialSection);
  40. }
  41. CRITICAL_SECTION* GetOSHandle()
  42. {
  43. return &m_CritialSection;
  44. }
  45. private:
  46. CRITICAL_SECTION m_CritialSection;
  47. };
  48. }
  49. }
  50. #endif