MutexImpl.h 846 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #pragma once
  2. #if IL2CPP_THREADS_PTHREAD
  3. #include <pthread.h>
  4. namespace il2cpp
  5. {
  6. namespace os
  7. {
  8. class FastMutexImpl
  9. {
  10. public:
  11. FastMutexImpl()
  12. {
  13. pthread_mutexattr_t attr;
  14. pthread_mutexattr_init(&attr);
  15. pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
  16. pthread_mutex_init(&m_Mutex, &attr);
  17. pthread_mutexattr_destroy(&attr);
  18. }
  19. ~FastMutexImpl()
  20. {
  21. pthread_mutex_destroy(&m_Mutex);
  22. }
  23. void Lock()
  24. {
  25. pthread_mutex_lock(&m_Mutex);
  26. }
  27. void Unlock()
  28. {
  29. pthread_mutex_unlock(&m_Mutex);
  30. }
  31. pthread_mutex_t* GetOSHandle()
  32. {
  33. return &m_Mutex;
  34. }
  35. private:
  36. pthread_mutex_t m_Mutex;
  37. };
  38. }
  39. }
  40. #endif