FastReaderReaderWriterLock.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #pragma once
  2. #include "utils/NonCopyable.h"
  3. namespace il2cpp
  4. {
  5. namespace os
  6. {
  7. class FastReaderReaderWriterLockImpl;
  8. // Use this class if the work done in the shared lock is "fast" - on the order of taking a lock
  9. class FastReaderReaderWriterLock
  10. {
  11. public:
  12. FastReaderReaderWriterLock();
  13. ~FastReaderReaderWriterLock();
  14. void LockExclusive();
  15. void LockShared();
  16. void ReleaseExclusive();
  17. void ReleaseShared();
  18. FastReaderReaderWriterLockImpl* GetImpl();
  19. private:
  20. FastReaderReaderWriterLockImpl* m_Impl;
  21. };
  22. struct FastReaderReaderWriterAutoSharedLock : public il2cpp::utils::NonCopyable
  23. {
  24. FastReaderReaderWriterAutoSharedLock(FastReaderReaderWriterLock* lock)
  25. : m_Lock(lock)
  26. {
  27. m_Lock->LockShared();
  28. }
  29. ~FastReaderReaderWriterAutoSharedLock()
  30. {
  31. m_Lock->ReleaseShared();
  32. }
  33. private:
  34. FastReaderReaderWriterLock* m_Lock;
  35. };
  36. struct FastReaderReaderWriterAutoExclusiveLock : public il2cpp::utils::NonCopyable
  37. {
  38. FastReaderReaderWriterAutoExclusiveLock(FastReaderReaderWriterLock* lock)
  39. : m_Lock(lock)
  40. {
  41. m_Lock->LockExclusive();
  42. }
  43. ~FastReaderReaderWriterAutoExclusiveLock()
  44. {
  45. m_Lock->ReleaseExclusive();
  46. }
  47. private:
  48. FastReaderReaderWriterLock* m_Lock;
  49. };
  50. }
  51. }