platform_mutex.c 772 B

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  2. * @Author: jiejie
  3. * @Github: https://github.com/jiejieTop
  4. * @Date: 2019-12-15 18:27:19
  5. * @LastEditTime: 2020-04-27 22:22:27
  6. * @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
  7. */
  8. #include "platform_mutex.h"
  9. int platform_mutex_init(platform_mutex_t* m)
  10. {
  11. m->mutex = xSemaphoreCreateMutex();
  12. return 0;
  13. }
  14. int platform_mutex_lock(platform_mutex_t* m)
  15. {
  16. return xSemaphoreTake(m->mutex, portMAX_DELAY);
  17. }
  18. int platform_mutex_trylock(platform_mutex_t* m)
  19. {
  20. return xSemaphoreTake(m->mutex, 0);
  21. }
  22. int platform_mutex_unlock(platform_mutex_t* m)
  23. {
  24. return xSemaphoreGive(m->mutex);
  25. }
  26. int platform_mutex_destroy(platform_mutex_t* m)
  27. {
  28. vSemaphoreDelete(m->mutex);
  29. return 0;
  30. }