F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Condition.cpp
Go to the documentation of this file.
1#include "Os/Condition.hpp"
2#include "Fw/Types/Assert.hpp"
3
4namespace Os {
5ConditionVariable::ConditionVariable() : m_delegate(*ConditionVariableInterface::getDelegate(m_handle_storage)) {}
6
10
12 FW_ASSERT(&this->m_delegate == reinterpret_cast<ConditionVariableInterface*>(&this->m_handle_storage[0]));
13 FW_ASSERT(this->m_lock == nullptr || this->m_lock == &mutex); // Confirm the same mutex used across waits
14 this->m_lock = &mutex;
15 // Attempt to lock the mutex and ensure that this was successful or the lock was already held
16 Mutex::Status lock_status = this->m_lock->take();
17 FW_ASSERT(lock_status == Mutex::Status::OP_OK || lock_status == Mutex::Status::ERROR_DEADLOCK);
18 this->m_delegate.wait(mutex);
19}
21 FW_ASSERT(&this->m_delegate == reinterpret_cast<ConditionVariableInterface*>(&this->m_handle_storage[0]));
22 this->m_delegate.notify();
23}
25 FW_ASSERT(&this->m_delegate == reinterpret_cast<ConditionVariableInterface*>(&this->m_handle_storage[0]));
26 this->m_delegate.notifyAll();
27}
28
30 FW_ASSERT(&this->m_delegate == reinterpret_cast<const ConditionVariableInterface*>(&this->m_handle_storage[0]));
31 return this->m_delegate.getHandle();
32}
33
34}
#define FW_ASSERT(...)
Definition Assert.hpp:14
Condition variable handle parent.
Definition Condition.hpp:14
void notifyAll() override
notify all waiters on this condition variable
Definition Condition.cpp:24
ConditionVariableHandle * getHandle() override
return the underlying condition variable handle (implementation specific). Delegates to implementatio...
Definition Condition.cpp:29
ConditionVariable()
default constructor
Definition Condition.cpp:5
~ConditionVariable() final
default virtual destructor
Definition Condition.cpp:7
void notify() override
notify a single waiter on this condition variable
Definition Condition.cpp:20
void wait(Os::Mutex &mutex) override
wait on a condition variable
Definition Condition.cpp:11
interface for condition variables
Definition Condition.hpp:20
virtual void notifyAll()=0
notify all waiters on this condition variable
virtual ~ConditionVariableInterface()=default
Default destructor.
virtual ConditionVariableHandle * getHandle()=0
return the underlying condition variable handle (implementation specific).
virtual void notify()=0
notify a single waiter on this condition variable
virtual void wait(Os::Mutex &mutex)=0
wait on a condition variable
Status take() override
lock the mutex and get return status
Definition Mutex.cpp:24
@ OP_OK
Operation was successful.
Definition Mutex.hpp:18
@ ERROR_DEADLOCK
Deadlock condition detected.
Definition Mutex.hpp:20