xref: /nrf52832-nimble/rt-thread/components/libc/compilers/dlib/rmtx.c (revision 042d53a763ad75cb1465103098bb88c245d95138)
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 /*
14  * for IAR compiler, we recommand to define _DLIB_THREAD_SUPPORT
15  * as 2 for dlib multi-thread support.
16  */
17 
18 #if _DLIB_THREAD_SUPPORT
19 typedef void* _Rmtx;
20 void _Mtxinit(_Rmtx *m)
21 {
22     rt_mutex_t mutex;
23 
24     RT_ASSERT(m != RT_NULL);
25 
26     mutex = (rt_mutex_t)m;
27     rt_mutex_init(mutex, "iarMtx", RT_IPC_FLAG_FIFO);
28 }
29 
30 void _Mtxdst(_Rmtx *m)
31 {
32     rt_mutex_t mutex;
33 
34     RT_ASSERT(m != RT_NULL);
35 
36     mutex = (rt_mutex_t)m;
37     rt_mutex_detach(mutex);
38 }
39 
40 void _Mtxlock(_Rmtx *m)
41 {
42     rt_mutex_t mutex;
43 
44     RT_ASSERT(m != RT_NULL);
45 
46     mutex = (rt_mutex_t)m;
47     rt_mutex_take(mutex, RT_WAITING_FOREVER);
48 }
49 
50 void _Mtxunlock(_Rmtx *m)
51 {
52     rt_mutex_t mutex;
53 
54     RT_ASSERT(m != RT_NULL);
55 
56     mutex = (rt_mutex_t)m;
57     rt_mutex_release(mutex);
58 }
59 #endif
60 
61