F´ Flight Software - C/C++ Documentation  devel
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 "Os/Posix/Mutex.hpp"
7 #include "Fw/Types/Assert.hpp"
8 
9 namespace Os {
10 namespace Posix {
11 namespace Mutex {
12 
14  PlatformIntType status = pthread_cond_init(&this->m_handle.m_condition, nullptr);
15  FW_ASSERT(status == 0, status); // If this fails, something horrible happened.
16 }
18  (void)pthread_cond_destroy(&this->m_handle.m_condition);
19 }
20 
22  PosixMutexHandle* mutex_handle = reinterpret_cast<PosixMutexHandle*>(mutex.getHandle());
23  FW_ASSERT(pthread_cond_wait(&this->m_handle.m_condition, &mutex_handle->m_mutex_descriptor) == 0);
24 }
26  FW_ASSERT(pthread_cond_signal(&this->m_handle.m_condition) == 0);
27 }
29  FW_ASSERT(pthread_cond_broadcast(&this->m_handle.m_condition) == 0);
30 }
31 
33  return &m_handle;
34 }
35 
36 }
37 }
38 }
#define FW_ASSERT(...)
Definition: Assert.hpp:14
int PlatformIntType
DefaultTypes.hpp provides fallback defaults for the platform types.
Condition variable handle parent.
Definition: Condition.hpp:14
MutexHandle * getHandle() override
return the underlying mutex handle (implementation specific)
Definition: Mutex.cpp:19
ConditionVariableHandle * getHandle() override
get handle
void notify() override
notify a single waiter
void wait(Os::Mutex &mutex) override
wait releasing mutex
void notifyAll() override
notify all current waiters
pthread_mutex_t m_mutex_descriptor
Definition: Mutex.hpp:15