F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
Loading...
Searching...
No Matches
Mutex.cpp
Go to the documentation of this file.
1// ======================================================================
2// \title Os/Posix/Mutex.cpp
3// \brief Posix implementation for Os::Mutex
4// ======================================================================
5#include <Os/Posix/Mutex.hpp>
6#include <Os/Posix/error.hpp>
7#include <Fw/Types/Assert.hpp>
8
9namespace Os {
10namespace Posix {
11namespace Mutex {
12
14 // set attributes
15 pthread_mutexattr_t attribute;
16 PlatformIntType status = pthread_mutexattr_init(&attribute);
17 FW_ASSERT(status == 0, status);
18
19 // set to normal mutex type
20 status = pthread_mutexattr_settype(&attribute, PTHREAD_MUTEX_ERRORCHECK);
21 FW_ASSERT(status == 0, status);
22
23 // set to check for priority inheritance
24 status = pthread_mutexattr_setprotocol(&attribute, PTHREAD_PRIO_INHERIT);
25 FW_ASSERT(status == 0, status);
26
27 status = pthread_mutex_init(&this->m_handle.m_mutex_descriptor, &attribute);
28 FW_ASSERT(status == 0, status);
29}
30
32 PlatformIntType status = pthread_mutex_destroy(&this->m_handle.m_mutex_descriptor);
33 FW_ASSERT(status == 0, status);
34}
35
37 PlatformIntType status = pthread_mutex_lock(&this->m_handle.m_mutex_descriptor);
39}
40
42 PlatformIntType status = pthread_mutex_unlock(&this->m_handle.m_mutex_descriptor);
44}
45
47 return &this->m_handle;
48}
49} // namespace Mutex
50} // namespace Posix
51} // namespace Os
#define FW_ASSERT(...)
Definition Assert.hpp:14
int PlatformIntType
DefaultTypes.hpp provides fallback defaults for the platform types.
~PosixMutex() override
destructor
Definition Mutex.cpp:31
Status release() override
unlock the mutex and get return status
Definition Mutex.cpp:41
MutexHandle * getHandle() override
return the underlying mutex handle (implementation specific)
Definition Mutex.cpp:46
Status take() override
lock the mutex and get return status
Definition Mutex.cpp:36
Mutex::Status posix_status_to_mutex_status(PlatformIntType posix_status)
Definition error.cpp:169
pthread_mutex_t m_mutex_descriptor
Definition Mutex.hpp:15