osmutex.cpp 619 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include "osmutex.h"
  2. int InitMutex(OSMutex *mutex)
  3. {
  4. #ifdef _WIN32
  5. InitializeCriticalSection(mutex);
  6. #else
  7. pthread_mutex_init(mutex, NULL);
  8. #endif
  9. return 0;
  10. }
  11. int LockMutex(OSMutex *mutex)
  12. {
  13. #ifdef _WIN32
  14. EnterCriticalSection(mutex);
  15. #else
  16. (void)pthread_mutex_lock(mutex);
  17. #endif
  18. return 0;
  19. }
  20. int UnlockMutex(OSMutex *mutex)
  21. {
  22. #ifdef _WIN32
  23. LeaveCriticalSection(mutex);
  24. #else
  25. pthread_mutex_unlock(mutex);
  26. #endif
  27. return 0;
  28. }
  29. int DeinitMutex(OSMutex *mutex)
  30. {
  31. #ifdef _WIN32
  32. DeleteCriticalSection(mutex);
  33. #else
  34. pthread_mutex_destroy(mutex);
  35. #endif
  36. return 0;
  37. }