µ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-2023 Liviu Ionescu. All rights reserved.
5
*
6
* Permission to use, copy, modify, and/or distribute this software
7
* for any purpose is hereby granted, under the terms of the MIT license.
8
*
9
* If a copy of the license was not distributed with this file, it can
10
* be obtained from https://opensource.org/licenses/mit/.
11
*/
12
13
#include <
cmsis-plus/estd/mutex
>
14
15
// ----------------------------------------------------------------------------
16
17
#if defined(__clang__)
18
#pragma clang diagnostic ignored "-Wc++98-compat"
19
#endif
20
21
// ----------------------------------------------------------------------------
22
23
namespace
os
24
{
25
namespace
estd
26
{
27
// ========================================================================
28
29
void
30
mutex::lock
()
31
{
32
os::rtos::result_t
res;
33
res =
nm_
.
lock
();
34
if
(res !=
os::rtos::result::ok
)
35
{
36
os::estd::__throw_cmsis_error
(
static_cast<
int
>
(res),
37
"mutex lock failed"
);
38
}
39
}
40
41
bool
42
mutex::try_lock
()
43
{
44
os::rtos::result_t
res;
45
res =
nm_
.
try_lock
();
46
if
(res ==
os::rtos::result::ok
)
47
{
48
return
true
;
49
}
50
else
if
(res == EWOULDBLOCK)
51
{
52
return
false
;
53
}
54
55
os::estd::__throw_cmsis_error
(
static_cast<
int
>
(res),
56
"mutex try_lock failed"
);
57
// return false;
58
}
59
60
void
61
mutex::unlock
()
62
{
63
os::rtos::result_t
res;
64
res =
nm_
.
unlock
();
65
if
(res !=
os::rtos::result::ok
)
66
{
67
os::estd::__throw_cmsis_error
(
static_cast<
int
>
(res),
68
"mutex unlock failed"
);
69
}
70
}
71
72
// ========================================================================
73
74
void
75
recursive_mutex::lock
()
76
{
77
os::rtos::result_t
res;
78
res =
nm_
.
lock
();
79
if
(res !=
os::rtos::result::ok
)
80
{
81
os::estd::__throw_cmsis_error
(
static_cast<
int
>
(res),
82
"recursive_mutex lock failed"
);
83
}
84
}
85
86
bool
87
recursive_mutex::try_lock
() noexcept
88
{
89
os::rtos::result_t
res;
90
res =
nm_
.
try_lock
();
91
if
(res ==
os::rtos::result::ok
)
92
{
93
return
true
;
94
}
95
else
if
(res == EWOULDBLOCK)
96
{
97
return
false
;
98
}
99
100
os::estd::__throw_cmsis_error
(
static_cast<
int
>
(res),
101
"recursive_mutex try_lock failed"
);
102
//return false;
103
}
104
105
void
106
recursive_mutex::unlock
()
107
{
108
os::rtos::result_t
res;
109
res =
nm_
.
unlock
();
110
if
(res !=
os::rtos::result::ok
)
111
{
112
os::estd::__throw_cmsis_error
(
static_cast<
int
>
(res),
113
"recursive_mutex unlock failed"
);
114
}
115
}
116
117
// ==========================================================================
118
119
}
/* namespace estd */
120
}
/* namespace os */
121
122
// ----------------------------------------------------------------------------
os::estd::mutex::nm_
native_type nm_
Definition
mutex:92
os::estd::mutex::lock
void lock()
Definition
mutex.cpp:30
os::estd::mutex::try_lock
bool try_lock()
Definition
mutex.cpp:42
os::estd::mutex::unlock
void unlock()
Definition
mutex.cpp:61
os::estd::recursive_mutex::nm_
native_type nm_
Definition
mutex:129
os::estd::recursive_mutex::try_lock
bool try_lock() noexcept
Definition
mutex.cpp:87
os::estd::recursive_mutex::lock
void lock()
Definition
mutex.cpp:75
os::estd::recursive_mutex::unlock
void unlock()
Definition
mutex.cpp:106
os::rtos::mutex::lock
result_t lock(void)
Lock/acquire the mutex.
Definition
os-mutex.cpp:955
os::rtos::mutex::try_lock
result_t try_lock(void)
Try to lock/acquire the mutex.
Definition
os-mutex.cpp:1076
os::rtos::mutex::unlock
result_t unlock(void)
Unlock/release the mutex.
Definition
os-mutex.cpp:1324
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:181
os::rtos::result_t
uint32_t result_t
Type of values returned by RTOS functions.
Definition
os-decls.h:96
os
System namespace.
src
libcpp
mutex.cpp
Generated by
1.9.7