| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // ====================================================================== | ||
| 2 | // \title Os/Posix/ConditionVariable.cpp | ||
| 3 | // \brief Posix implementations for Os::ConditionVariable | ||
| 4 | // ====================================================================== | ||
| 5 | #include "Os/Posix/ConditionVariable.hpp" | ||
| 6 | #include "Fw/Types/Assert.hpp" | ||
| 7 | #include "Os/Posix/Mutex.hpp" | ||
| 8 | #include "Os/Posix/error.hpp" | ||
| 9 | |||
| 10 | namespace Os { | ||
| 11 | namespace Posix { | ||
| 12 | namespace Mutex { | ||
| 13 | |||
| 14 | 2961 | PosixConditionVariable::PosixConditionVariable() { | |
| 15 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 2961 times.
|
2961 | int status = pthread_cond_init(&this->m_handle.m_condition, nullptr); |
| 16 | 2961 | FW_ASSERT(status == 0, static_cast<FwAssertArgType>(status)); // If this fails, something horrible happened. | |
| 17 | 2961 | } | |
| 18 | 5922 | PosixConditionVariable::~PosixConditionVariable() { | |
| 19 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 2961 times.
|
5922 | (void)pthread_cond_destroy(&this->m_handle.m_condition); |
| 20 | 5922 | } | |
| 21 | |||
| 22 | 12 | PosixConditionVariable::Status PosixConditionVariable::pend(Os::Mutex& mutex) { | |
| 23 | 12 | PosixMutexHandle* mutex_handle = reinterpret_cast<PosixMutexHandle*>(mutex.getHandle()); | |
| 24 | 12 | FW_ASSERT(mutex_handle != nullptr); | |
| 25 |
2/4✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 12 times.
|
12 | int status = pthread_cond_wait(&this->m_handle.m_condition, &mutex_handle->m_mutex_descriptor); |
| 26 | 12 | return posix_status_to_conditional_status(status); | |
| 27 | } | ||
| 28 | 257053 | void PosixConditionVariable::notify() { | |
| 29 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 257053 times.
|
257053 | const int status = pthread_cond_signal(&this->m_handle.m_condition); |
| 30 | 257053 | FW_ASSERT(status == 0); | |
| 31 | 257053 | } | |
| 32 | 1 | void PosixConditionVariable::notifyAll() { | |
| 33 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | const int status = pthread_cond_broadcast(&this->m_handle.m_condition); |
| 34 | 1 | FW_ASSERT(status == 0); | |
| 35 | 1 | } | |
| 36 | |||
| 37 | ✗ | ConditionVariableHandle* PosixConditionVariable::getHandle() { | |
| 38 | ✗ | return &m_handle; | |
| 39 | } | ||
| 40 | |||
| 41 | } // namespace Mutex | ||
| 42 | } // namespace Posix | ||
| 43 | } // namespace Os | ||
| 44 |