ReaderWriterLockImpl.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #pragma once
  2. #include "il2cpp-config.h"
  3. #if IL2CPP_THREADS_PTHREAD && IL2CPP_SUPPORT_THREADS
  4. #include <pthread.h>
  5. namespace il2cpp
  6. {
  7. namespace os
  8. {
  9. class ReaderWriterLockImpl
  10. {
  11. public:
  12. ReaderWriterLockImpl()
  13. {
  14. int result = pthread_rwlock_init(&m_Lock, NULL);
  15. NO_UNUSED_WARNING(result);
  16. IL2CPP_ASSERT(result == 0);
  17. }
  18. ~ReaderWriterLockImpl()
  19. {
  20. int result = pthread_rwlock_destroy(&m_Lock);
  21. NO_UNUSED_WARNING(result);
  22. IL2CPP_ASSERT(result == 0);
  23. }
  24. void LockExclusive()
  25. {
  26. int result = pthread_rwlock_wrlock(&m_Lock);
  27. NO_UNUSED_WARNING(result);
  28. IL2CPP_ASSERT(result == 0);
  29. }
  30. void LockShared()
  31. {
  32. int result = pthread_rwlock_rdlock(&m_Lock);
  33. NO_UNUSED_WARNING(result);
  34. IL2CPP_ASSERT(result == 0);
  35. }
  36. void ReleaseExclusive()
  37. {
  38. int result = pthread_rwlock_unlock(&m_Lock);
  39. NO_UNUSED_WARNING(result);
  40. IL2CPP_ASSERT(result == 0);
  41. }
  42. void ReleaseShared()
  43. {
  44. int result = pthread_rwlock_unlock(&m_Lock);
  45. NO_UNUSED_WARNING(result);
  46. IL2CPP_ASSERT(result == 0);
  47. }
  48. pthread_rwlock_t* GetOSHandle()
  49. {
  50. return &m_Lock;
  51. }
  52. private:
  53. pthread_rwlock_t m_Lock;
  54. };
  55. }
  56. }
  57. #endif