MutexImpl.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. void* GetOSHandle();
  20. private:
  21. HANDLE m_MutexHandle;
  22. };
  23. class FastMutexImpl
  24. {
  25. public:
  26. FastMutexImpl()
  27. {
  28. InitializeCriticalSection(&m_CritialSection);
  29. }
  30. ~FastMutexImpl()
  31. {
  32. DeleteCriticalSection(&m_CritialSection);
  33. }
  34. void Lock()
  35. {
  36. EnterCriticalSection(&m_CritialSection);
  37. }
  38. void Unlock()
  39. {
  40. LeaveCriticalSection(&m_CritialSection);
  41. }
  42. CRITICAL_SECTION* GetOSHandle()
  43. {
  44. return &m_CritialSection;
  45. }
  46. private:
  47. CRITICAL_SECTION m_CritialSection;
  48. };
  49. }
  50. }
  51. #endif