rmtx.c 1010 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2015-01-28 Bernard first version
  9. */
  10. #include <rtthread.h>
  11. #include <yfuns.h>
  12. /*
  13. * for IAR compiler, we recommand to define _DLIB_THREAD_SUPPORT
  14. * as 2 for dlib multi-thread support.
  15. */
  16. #if _DLIB_THREAD_SUPPORT
  17. typedef void* _Rmtx;
  18. void _Mtxinit(_Rmtx *m)
  19. {
  20. rt_mutex_t mutex;
  21. RT_ASSERT(m != RT_NULL);
  22. mutex = (rt_mutex_t)m;
  23. rt_mutex_init(mutex, "iarMtx", RT_IPC_FLAG_FIFO);
  24. }
  25. void _Mtxdst(_Rmtx *m)
  26. {
  27. rt_mutex_t mutex;
  28. RT_ASSERT(m != RT_NULL);
  29. mutex = (rt_mutex_t)m;
  30. rt_mutex_detach(mutex);
  31. }
  32. void _Mtxlock(_Rmtx *m)
  33. {
  34. rt_mutex_t mutex;
  35. RT_ASSERT(m != RT_NULL);
  36. mutex = (rt_mutex_t)m;
  37. rt_mutex_take(mutex, RT_WAITING_FOREVER);
  38. }
  39. void _Mtxunlock(_Rmtx *m)
  40. {
  41. rt_mutex_t mutex;
  42. RT_ASSERT(m != RT_NULL);
  43. mutex = (rt_mutex_t)m;
  44. rt_mutex_release(mutex);
  45. }
  46. #endif