F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
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 
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 
35  return &this->m_handle;
36 }
37 } // namespace Mutex
38 } // namespace Stub
39 } // namespace Os
Operation succeeded.
Definition: Os.hpp:26
MutexHandle * getHandle() override
return the underlying mutex handle (implementation specific)
Definition: Mutex.cpp:34
Status release() override
unlock the mutex and get return status
Definition: Mutex.cpp:23
Status take() override
lock the mutex and get return status
Definition: Mutex.cpp:11
std::atomic< bool > m_mutex_taken
True if the mutex has been acquired without being released.
Definition: Mutex.hpp:17