| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // ====================================================================== | ||
| 2 | // \title Os/Posix/Mutex.cpp | ||
| 3 | // \brief Posix implementation for Os::Mutex | ||
| 4 | // ====================================================================== | ||
| 5 | #include <Fw/Types/Assert.hpp> | ||
| 6 | #include <Os/Posix/Mutex.hpp> | ||
| 7 | #include <Os/Posix/error.hpp> | ||
| 8 | |||
| 9 | namespace Os { | ||
| 10 | namespace Posix { | ||
| 11 | namespace Mutex { | ||
| 12 | |||
| 13 | 1273 | PosixMutex::PosixMutex() : Os::MutexInterface(), m_handle() { | |
| 14 | // set attributes | ||
| 15 | 1273 | pthread_mutexattr_t attribute; | |
| 16 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1273 times.
|
1273 | int status = pthread_mutexattr_init(&attribute); |
| 17 | 1273 | FW_ASSERT(status == 0, static_cast<FwAssertArgType>(status)); | |
| 18 | |||
| 19 | // set to normal mutex type | ||
| 20 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1273 times.
|
1273 | status = pthread_mutexattr_settype(&attribute, PTHREAD_MUTEX_ERRORCHECK); |
| 21 | 1273 | FW_ASSERT(status == 0, static_cast<FwAssertArgType>(status)); | |
| 22 | |||
| 23 | // set to check for priority inheritance | ||
| 24 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1273 times.
|
1273 | status = pthread_mutexattr_setprotocol(&attribute, PTHREAD_PRIO_INHERIT); |
| 25 | 1273 | FW_ASSERT(status == 0, static_cast<FwAssertArgType>(status)); | |
| 26 | |||
| 27 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 1273 times.
|
1273 | status = pthread_mutex_init(&this->m_handle.m_mutex_descriptor, &attribute); |
| 28 | 1273 | FW_ASSERT(status == 0, static_cast<FwAssertArgType>(status)); | |
| 29 | 1273 | } | |
| 30 | |||
| 31 | 2546 | PosixMutex::~PosixMutex() { | |
| 32 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 1273 times.
|
2546 | int status = pthread_mutex_destroy(&this->m_handle.m_mutex_descriptor); |
| 33 | 2546 | FW_ASSERT(status == 0, static_cast<FwAssertArgType>(status)); | |
| 34 | 2546 | } | |
| 35 | |||
| 36 | 10783210 | PosixMutex::Status PosixMutex::take() { | |
| 37 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 12475054 times.
|
10783210 | int status = pthread_mutex_lock(&this->m_handle.m_mutex_descriptor); |
| 38 | 10994575 | return Os::Posix::posix_status_to_mutex_status(status); | |
| 39 | } | ||
| 40 | |||
| 41 | 10064387 | PosixMutex::Status PosixMutex::release() { | |
| 42 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 12750915 times.
|
10064387 | int status = pthread_mutex_unlock(&this->m_handle.m_mutex_descriptor); |
| 43 | 11916342 | return Os::Posix::posix_status_to_mutex_status(status); | |
| 44 | } | ||
| 45 | |||
| 46 | 10 | MutexHandle* PosixMutex::getHandle() { | |
| 47 | 10 | return &this->m_handle; | |
| 48 | } | ||
| 49 | } // namespace Mutex | ||
| 50 | } // namespace Posix | ||
| 51 | } // namespace Os | ||
| 52 |