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
9
namespace
Os
{
10
namespace
Posix {
11
namespace
Mutex {
12
13
PosixMutex::PosixMutex
() :
Os
::
MutexInterface
(), m_handle() {
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
31
PosixMutex::~PosixMutex
() {
32
PlatformIntType
status = pthread_mutex_destroy(&this->m_handle.
m_mutex_descriptor
);
33
FW_ASSERT
(status == 0, status);
34
}
35
36
PosixMutex::Status
PosixMutex::take
() {
37
PlatformIntType
status = pthread_mutex_lock(&this->m_handle.
m_mutex_descriptor
);
38
return
Os::Posix::posix_status_to_mutex_status
(status);
39
}
40
41
PosixMutex::Status
PosixMutex::release
() {
42
PlatformIntType
status = pthread_mutex_unlock(&this->m_handle.
m_mutex_descriptor
);
43
return
Os::Posix::posix_status_to_mutex_status
(status);
44
}
45
46
MutexHandle
*
PosixMutex::getHandle
() {
47
return
&this->m_handle;
48
}
49
}
// namespace Mutex
50
}
// namespace Posix
51
}
// namespace Os
Assert.hpp
FW_ASSERT
#define FW_ASSERT(...)
Definition
Assert.hpp:14
PlatformIntType
int PlatformIntType
DefaultTypes.hpp provides fallback defaults for the platform types.
Definition
DefaultTypes.hpp:13
Mutex.hpp
Os::MutexInterface
Definition
Mutex.hpp:15
Os::MutexInterface::Status
Status
Definition
Mutex.hpp:17
Os::Posix::Mutex::PosixMutex::~PosixMutex
~PosixMutex() override
destructor
Definition
Mutex.cpp:31
Os::Posix::Mutex::PosixMutex::PosixMutex
PosixMutex()
constructor
Definition
Mutex.cpp:13
Os::Posix::Mutex::PosixMutex::release
Status release() override
unlock the mutex and get return status
Definition
Mutex.cpp:41
Os::Posix::Mutex::PosixMutex::getHandle
MutexHandle * getHandle() override
return the underlying mutex handle (implementation specific)
Definition
Mutex.cpp:46
Os::Posix::Mutex::PosixMutex::take
Status take() override
lock the mutex and get return status
Definition
Mutex.cpp:36
error.hpp
Os::Posix::posix_status_to_mutex_status
Mutex::Status posix_status_to_mutex_status(PlatformIntType posix_status)
Definition
error.cpp:169
Os
Definition
DirectoryOpenModeEnumAc.cpp:13
Os::MutexHandle
Definition
Mutex.hpp:13
Os::Posix::Mutex::PosixMutexHandle::m_mutex_descriptor
pthread_mutex_t m_mutex_descriptor
Definition
Mutex.hpp:15
Os
Posix
Mutex.cpp
Generated by
1.9.8