ReaderWriterLock.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #pragma once
  2. #include "utils/NonCopyable.h"
  3. namespace il2cpp
  4. {
  5. namespace os
  6. {
  7. class ReaderWriterLockImpl;
  8. class ReaderWriterLock
  9. {
  10. public:
  11. ReaderWriterLock();
  12. ~ReaderWriterLock();
  13. void LockExclusive();
  14. void LockShared();
  15. void ReleaseExclusive();
  16. void ReleaseShared();
  17. ReaderWriterLockImpl* GetImpl();
  18. private:
  19. ReaderWriterLockImpl* m_Impl;
  20. };
  21. struct ReaderWriterAutoSharedLock : public il2cpp::utils::NonCopyable
  22. {
  23. ReaderWriterAutoSharedLock(ReaderWriterLock* lock)
  24. : m_Lock(lock)
  25. {
  26. m_Lock->LockShared();
  27. }
  28. ~ReaderWriterAutoSharedLock()
  29. {
  30. m_Lock->ReleaseShared();
  31. }
  32. private:
  33. ReaderWriterLock* m_Lock;
  34. };
  35. struct ReaderWriterAutoExclusiveLock : public il2cpp::utils::NonCopyable
  36. {
  37. ReaderWriterAutoExclusiveLock(ReaderWriterLock* lock)
  38. : m_Lock(lock)
  39. {
  40. m_Lock->LockExclusive();
  41. }
  42. ~ReaderWriterAutoExclusiveLock()
  43. {
  44. m_Lock->ReleaseExclusive();
  45. }
  46. private:
  47. ReaderWriterLock* m_Lock;
  48. };
  49. }
  50. }