F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
ConditionVariable.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title Os/Posix/ConditionVariable.cpp
3 // \brief Posix implementations for Os::ConditionVariable
4 // ======================================================================
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 
15  PlatformIntType status = pthread_cond_init(&this->m_handle.m_condition, nullptr);
16  FW_ASSERT(status == 0, status); // If this fails, something horrible happened.
17 }
19  (void)pthread_cond_destroy(&this->m_handle.m_condition);
20 }
21 
23  PosixMutexHandle* mutex_handle = reinterpret_cast<PosixMutexHandle*>(mutex.getHandle());
24  PlatformIntType status = pthread_cond_wait(&this->m_handle.m_condition, &mutex_handle->m_mutex_descriptor);
26 }
28  FW_ASSERT(pthread_cond_signal(&this->m_handle.m_condition) == 0);
29 }
31  FW_ASSERT(pthread_cond_broadcast(&this->m_handle.m_condition) == 0);
32 }
33 
35  return &m_handle;
36 }
37 
38 } // namespace Mutex
39 } // namespace Posix
40 } // namespace Os
void notify() override
notify a single waiter
void notifyAll() override
notify all current waiters
MutexHandle * getHandle() override
return the underlying mutex handle (implementation specific)
Definition: Mutex.cpp:19
int PlatformIntType
DefaultTypes.hpp provides fallback defaults for the platform types.
PosixConditionVariable::Status pend(Os::Mutex &mutex) override
wait releasing mutex
pthread_mutex_t m_mutex_descriptor
Definition: Mutex.hpp:15
Condition variable handle parent.
Definition: Condition.hpp:14
ConditionVariableHandle * getHandle() override
get handle
ConditionVariable::Status posix_status_to_conditional_status(PlatformIntType posix_status)
Definition: error.cpp:188
#define FW_ASSERT(...)
Definition: Assert.hpp:14