µ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++ distribution.
3
* (https://github.com/micro-os-plus)
4
* Copyright (c) 2016 Liviu Ionescu.
5
*
6
* Permission is hereby granted, free of charge, to any person
7
* obtaining a copy of this software and associated documentation
8
* files (the "Software"), to deal in the Software without
9
* restriction, including without limitation the rights to use,
10
* copy, modify, merge, publish, distribute, sublicense, and/or
11
* sell copies of the Software, and to permit persons to whom
12
* the Software is furnished to do so, subject to the following
13
* conditions:
14
*
15
* The above copyright notice and this permission notice shall be
16
* included in all copies or substantial portions of the Software.
17
*
18
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25
* OTHER DEALINGS IN THE SOFTWARE.
26
*/
27
28
#include <
cmsis-plus/estd/mutex
>
29
30
// ----------------------------------------------------------------------------
31
32
#if defined(__clang__)
33
#pragma clang diagnostic ignored "-Wc++98-compat"
34
#endif
35
36
// ----------------------------------------------------------------------------
37
38
namespace
os
39
{
40
namespace
estd
41
{
42
// ========================================================================
43
44
void
45
mutex::lock
()
46
{
47
os::rtos::result_t
res;
48
res =
nm_
.
lock
();
49
if
(res !=
os::rtos::result::ok
)
50
{
51
os::estd::__throw_cmsis_error
(
static_cast<
int
>
(res),
52
"mutex lock failed"
);
53
}
54
}
55
56
bool
57
mutex::try_lock
()
58
{
59
os::rtos::result_t
res;
60
res =
nm_
.
try_lock
();
61
if
(res ==
os::rtos::result::ok
)
62
{
63
return
true
;
64
}
65
else
if
(res == EWOULDBLOCK)
66
{
67
return
false
;
68
}
69
70
os::estd::__throw_cmsis_error
(
static_cast<
int
>
(res),
71
"mutex try_lock failed"
);
72
// return false;
73
}
74
75
void
76
mutex::unlock
()
77
{
78
os::rtos::result_t
res;
79
res =
nm_
.
unlock
();
80
if
(res !=
os::rtos::result::ok
)
81
{
82
os::estd::__throw_cmsis_error
(
static_cast<
int
>
(res),
83
"mutex unlock failed"
);
84
}
85
}
86
87
// ========================================================================
88
89
void
90
recursive_mutex::lock
()
91
{
92
os::rtos::result_t
res;
93
res =
nm_
.
lock
();
94
if
(res !=
os::rtos::result::ok
)
95
{
96
os::estd::__throw_cmsis_error
(
static_cast<
int
>
(res),
97
"recursive_mutex lock failed"
);
98
}
99
}
100
101
bool
102
recursive_mutex::try_lock
() noexcept
103
{
104
os::rtos::result_t
res;
105
res =
nm_
.
try_lock
();
106
if
(res ==
os::rtos::result::ok
)
107
{
108
return
true
;
109
}
110
else
if
(res == EWOULDBLOCK)
111
{
112
return
false
;
113
}
114
115
os::estd::__throw_cmsis_error
(
static_cast<
int
>
(res),
116
"recursive_mutex try_lock failed"
);
117
//return false;
118
}
119
120
void
121
recursive_mutex::unlock
()
122
{
123
os::rtos::result_t
res;
124
res =
nm_
.
unlock
();
125
if
(res !=
os::rtos::result::ok
)
126
{
127
os::estd::__throw_cmsis_error
(
static_cast<
int
>
(res),
128
"recursive_mutex unlock failed"
);
129
}
130
}
131
132
// ==========================================================================
133
134
}
/* namespace estd */
135
}
/* namespace os */
136
137
// ----------------------------------------------------------------------------
os::estd::mutex::nm_
native_type nm_
Definition
mutex:108
os::estd::mutex::lock
void lock()
Definition
mutex.cpp:45
os::estd::mutex::try_lock
bool try_lock()
Definition
mutex.cpp:57
os::estd::mutex::unlock
void unlock()
Definition
mutex.cpp:76
os::estd::recursive_mutex::nm_
native_type nm_
Definition
mutex:145
os::estd::recursive_mutex::try_lock
bool try_lock() noexcept
Definition
mutex.cpp:102
os::estd::recursive_mutex::lock
void lock()
Definition
mutex.cpp:90
os::estd::recursive_mutex::unlock
void unlock()
Definition
mutex.cpp:121
os::rtos::mutex::lock
result_t lock(void)
Lock/acquire the mutex.
Definition
os-mutex.cpp:953
os::rtos::mutex::try_lock
result_t try_lock(void)
Try to lock/acquire the mutex.
Definition
os-mutex.cpp:1074
os::rtos::mutex::unlock
result_t unlock(void)
Unlock/release the mutex.
Definition
os-mutex.cpp:1310
mutex
os::estd::__throw_cmsis_error
void __throw_cmsis_error(int ev, const char *what_arg)
Definition
system-error.cpp:131
os::rtos::result::ok
@ ok
Function completed; no errors or events occurred.
Definition
os-decls.h:195
os::rtos::result_t
uint32_t result_t
Type of values returned by RTOS functions.
Definition
os-decls.h:110
os
System namespace.
src
libcpp
mutex.cpp
Generated by
1.9.7