µOS++ IIIe Reference
7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
mutex.cpp
Go to the documentation of this file.
1
/*
2
* This file is part of the µOS++ project (https://micro-os-plus.github.io/).
3
* Copyright (c) 2016-2025 Liviu Ionescu. All rights reserved.
4
*
5
* Permission to use, copy, modify, and/or distribute this software
6
* for any purpose is hereby granted, under the terms of the MIT license.
7
*
8
* If a copy of the license was not distributed with this file, it can
9
* be obtained from https://opensource.org/licenses/mit.
10
*/
11
12
#include <
cmsis-plus/estd/mutex
>
13
14
// ----------------------------------------------------------------------------
15
16
#if defined(__clang__)
17
#pragma clang diagnostic ignored "-Wc++98-compat"
18
#endif
19
20
// ----------------------------------------------------------------------------
21
22
namespace
os
23
{
24
namespace
estd
25
{
26
// ========================================================================
27
28
void
29
mutex::lock
()
30
{
31
os::rtos::result_t
res;
32
res =
nm_
.
lock
();
33
if
(res !=
os::rtos::result::ok
)
34
{
35
os::estd::__throw_cmsis_error
(
static_cast<
int
>
(res),
36
"mutex lock failed"
);
37
}
38
}
39
40
bool
41
mutex::try_lock
()
42
{
43
os::rtos::result_t
res;
44
res =
nm_
.
try_lock
();
45
if
(res ==
os::rtos::result::ok
)
46
{
47
return
true
;
48
}
49
else
if
(res == EWOULDBLOCK)
50
{
51
return
false
;
52
}
53
54
os::estd::__throw_cmsis_error
(
static_cast<
int
>
(res),
55
"mutex try_lock failed"
);
56
// return false;
57
}
58
59
void
60
mutex::unlock
()
61
{
62
os::rtos::result_t
res;
63
res =
nm_
.
unlock
();
64
if
(res !=
os::rtos::result::ok
)
65
{
66
os::estd::__throw_cmsis_error
(
static_cast<
int
>
(res),
67
"mutex unlock failed"
);
68
}
69
}
70
71
// ========================================================================
72
73
void
74
recursive_mutex::lock
()
75
{
76
os::rtos::result_t
res;
77
res =
nm_
.
lock
();
78
if
(res !=
os::rtos::result::ok
)
79
{
80
os::estd::__throw_cmsis_error
(
static_cast<
int
>
(res),
81
"recursive_mutex lock failed"
);
82
}
83
}
84
85
bool
86
recursive_mutex::try_lock
() noexcept
87
{
88
os::rtos::result_t
res;
89
res =
nm_
.
try_lock
();
90
if
(res ==
os::rtos::result::ok
)
91
{
92
return
true
;
93
}
94
else
if
(res == EWOULDBLOCK)
95
{
96
return
false
;
97
}
98
99
os::estd::__throw_cmsis_error
(
static_cast<
int
>
(res),
100
"recursive_mutex try_lock failed"
);
101
// return false;
102
}
103
104
void
105
recursive_mutex::unlock
()
106
{
107
os::rtos::result_t
res;
108
res =
nm_
.
unlock
();
109
if
(res !=
os::rtos::result::ok
)
110
{
111
os::estd::__throw_cmsis_error
(
static_cast<
int
>
(res),
112
"recursive_mutex unlock failed"
);
113
}
114
}
115
116
// ========================================================================
117
118
}
/* namespace estd */
119
}
/* namespace os */
120
121
// ----------------------------------------------------------------------------
os::estd::mutex::nm_
native_type nm_
Definition
mutex:89
os::estd::mutex::lock
void lock()
Definition
mutex.cpp:29
os::estd::mutex::try_lock
bool try_lock()
Definition
mutex.cpp:41
os::estd::mutex::unlock
void unlock()
Definition
mutex.cpp:60
os::estd::recursive_mutex::nm_
native_type nm_
Definition
mutex:124
os::estd::recursive_mutex::try_lock
bool try_lock() noexcept
Definition
mutex.cpp:86
os::estd::recursive_mutex::lock
void lock()
Definition
mutex.cpp:74
os::estd::recursive_mutex::unlock
void unlock()
Definition
mutex.cpp:105
os::rtos::mutex::lock
result_t lock(void)
Lock/acquire the mutex.
Definition
os-mutex.cpp:1003
os::rtos::mutex::try_lock
result_t try_lock(void)
Try to lock/acquire the mutex.
Definition
os-mutex.cpp:1126
os::rtos::mutex::unlock
result_t unlock(void)
Unlock/release the mutex.
Definition
os-mutex.cpp:1379
mutex
os::estd::__throw_cmsis_error
void __throw_cmsis_error(int ev, const char *what_arg)
Definition
system-error.cpp:124
os::rtos::result::ok
@ ok
Function completed; no errors or events occurred.
Definition
os-decls.h:179
os::rtos::result_t
uint32_t result_t
Type of values returned by RTOS functions.
Definition
os-decls.h:95
os
System namespace.
src
libcpp
mutex.cpp
Generated by
1.9.7