1
2
3
4
5
6 #include <cmajor/rt/Mutex.hpp>
7 #include <soulng/util/Error.hpp>
8 #include <mutex>
9
10 void* RtAllocateMutex()
11 {
12 return new std::mutex();
13 }
14
15 void RtFreeMutex(void* nativeHandle)
16 {
17 if (nativeHandle)
18 {
19 delete static_cast<std::mutex*>(nativeHandle);
20 }
21 }
22
23 void RtLockMutex(void* nativeHandle)
24 {
25 std::mutex* mtx = static_cast<std::mutex*>(nativeHandle);
26 mtx->lock();
27 }
28
29 void RtUnlockMutex(void* nativeHandle)
30 {
31 std::mutex* mtx = static_cast<std::mutex*>(nativeHandle);
32 mtx->unlock();
33 }
34
35 void* RtAllocateRecursiveMutex()
36 {
37 return new std::recursive_mutex();
38 }
39
40 void RtFreeRecursiveMutex(void* nativeHandle)
41 {
42 if (nativeHandle)
43 {
44 delete static_cast<std::recursive_mutex*>(nativeHandle);
45 }
46 }
47
48 void RtLockRecursiveMutex(void* nativeHandle)
49 {
50 std::recursive_mutex* mtx = static_cast<std::recursive_mutex*>(nativeHandle);
51 mtx->lock();
52 }
53
54 void RtUnlockRecursiveMutex(void* nativeHandle)
55 {
56 std::recursive_mutex* mtx = static_cast<std::recursive_mutex*>(nativeHandle);
57 mtx->unlock();
58 }