synch.c 901 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include "synch.h"
  2. /*
  3. #include "memutil.h"
  4. TOOLKIT_API int toolkit_mutex_create(toolkit_mutex_t** p_mutex)
  5. {
  6. toolkit_mutex_t* mutex;
  7. mutex = MALLOC_T(toolkit_mutex_t);
  8. *p_mutex = mutex;
  9. return 0;
  10. }
  11. TOOLKIT_API int toolkit_mutex_init(toolkit_mutex_t* mutex)
  12. {
  13. #ifdef _WIN32
  14. InitializeCriticalSection(mutex);
  15. #else
  16. #endif
  17. FREE(mutex);
  18. return 0;
  19. }
  20. TOOLKIT_API void toolkit_mutex_destroy(toolkit_mutex_t* mutex)
  21. {
  22. #ifdef _WIN32
  23. DeleteCriticalSection(mutex);
  24. #else
  25. #endif
  26. }
  27. TOOLKIT_API void toolkit_mutex_lock(toolkit_mutex_t* mutex)
  28. {
  29. #ifdef _WIN32
  30. EnterCriticalSection(mutex);
  31. #else
  32. #endif
  33. }
  34. TOOLKIT_API int toolkit_mutex_trylock(toolkit_mutex_t* mutex)
  35. {
  36. #ifdef _WIN32
  37. if(TryEnterCriticalSection(mutex))
  38. {
  39. return 0;
  40. }
  41. return -1;
  42. #else
  43. #endif
  44. return 0;
  45. }
  46. TOOLKIT_API void toolkit_mutex_unlock(toolkit_mutex_t* mutex)
  47. {
  48. #ifdef _WIN32
  49. LeaveCriticalSection(mutex);
  50. #else
  51. #endif
  52. }
  53. */