platform_mutex.c 806 B

12345678910111213141516171819202122232425262728293031323334
  1. /*
  2. * @Author: jiejie
  3. * @Github: https://github.com/jiejieTop
  4. * @Date: 2019-12-15 18:27:19
  5. * @LastEditTime : 2020-01-08 20:23:13
  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 = rt_mutex_create("platform_mutex", RT_IPC_FLAG_PRIO);
  12. return 0;
  13. }
  14. int platform_mutex_lock(platform_mutex_t* m)
  15. {
  16. return rt_mutex_take((m->mutex), RT_WAITING_FOREVER);
  17. }
  18. int platform_mutex_trylock(platform_mutex_t* m)
  19. {
  20. return rt_mutex_take((m->mutex), 0);
  21. }
  22. int platform_mutex_unlock(platform_mutex_t* m)
  23. {
  24. return rt_mutex_release((m->mutex));
  25. }
  26. int platform_mutex_destroy(platform_mutex_t* m)
  27. {
  28. return rt_mutex_delete((m->mutex));
  29. }