F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
Mutex.cpp
Go to the documentation of this file.
1
// ======================================================================
2
// \title Os/Stub/Mutex.cpp
3
// \brief stub implementation for Os::Mutex
4
// ======================================================================
5
#include "
Os/Stub/Mutex.hpp
"
6
7
namespace
Os
{
8
namespace
Stub {
9
namespace
Mutex
{
10
11
StubMutex::Status
StubMutex::take
() {
12
// Attempt to mark the mutex as taken.
13
if
(this->m_handle.
m_mutex_taken
.exchange(
true
)) {
14
// The mutex was already taken, so fail the operation.
15
// (This stub is for platforms without the ability to block.)
16
return
Status::ERROR_BUSY;
17
}
18
// The mutex was not already taken.
19
// Now that it has been marked as taken, we have successfully entered the critical section.
20
return
Status::OP_OK
;
21
}
22
23
StubMutex::Status
StubMutex::release
() {
24
// Attempt to mark the mutex as not taken.
25
if
(!this->m_handle.
m_mutex_taken
.exchange(
false
)) {
26
// The mutex was already not taken, which indicates a coding defect.
27
return
Status::ERROR_OTHER;
28
}
29
// The mutex was taken.
30
// Now that it has been marked as not taken, we have successfully exited the critical section.
31
return
Status::OP_OK
;
32
}
33
34
MutexHandle
*
StubMutex::getHandle
() {
35
return
&this->m_handle;
36
}
37
}
// namespace Mutex
38
}
// namespace Stub
39
}
// namespace Os
Os::Mutex
DelegateMutex Mutex
Definition:
OsSelection.hpp:102
Os::Generic::OP_OK
Operation succeeded.
Definition:
Os.hpp:27
Os::Stub::Mutex::StubMutex::getHandle
MutexHandle * getHandle() override
return the underlying mutex handle (implementation specific)
Definition:
Mutex.cpp:34
Os::Stub::Mutex::StubMutex::release
Status release() override
unlock the mutex and get return status
Definition:
Mutex.cpp:23
Os::Stub::Mutex::StubMutex::take
Status take() override
lock the mutex and get return status
Definition:
Mutex.cpp:11
Os
Definition:
LocklessQueueCfg.hpp:16
Os::Stub::Mutex::StubMutexHandle::m_mutex_taken
std::atomic< bool > m_mutex_taken
True if the mutex has been acquired without being released.
Definition:
Mutex.hpp:17
Os::MutexInterface::Status
Status
Definition:
MutexInterface.hpp:19
Os::MutexHandle
Definition:
MutexInterface.hpp:15
Mutex.hpp
Os
Stub
Mutex.cpp
Generated by
1.8.14