F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
Condition.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title Os/Condition.hpp
3 // \brief common function definitions for Os::ConditionVariables
4 // ======================================================================
5 #include "Os/Mutex.hpp"
6 #include "Os/Os.hpp"
7 
8 #ifndef OS_CONDITION_HPP_
9 #define OS_CONDITION_HPP_
10 
11 namespace Os {
12 
15 
21  public:
22  enum Status {
28  };
29 
31  ConditionVariableInterface() = default;
33  virtual ~ConditionVariableInterface() = default;
34 
37 
39  virtual ConditionVariableInterface& operator=(const ConditionVariableInterface& other) = delete;
40 
49  virtual Status pend(Os::Mutex& mutex) = 0;
50 
55  virtual void notify() = 0;
56 
61  virtual void notifyAll() = 0;
62 
65  virtual ConditionVariableHandle* getHandle() = 0;
66 
69 };
70 
76  public:
79 
81  ~ConditionVariable() final;
82 
84  ConditionVariable(const ConditionVariableInterface& other) = delete;
85 
87  ConditionVariable(const ConditionVariableInterface* other) = delete;
88 
90  ConditionVariableInterface& operator=(const ConditionVariableInterface& other) override = delete;
91 
104  Status pend(Os::Mutex& mutex) override;
105 
117  void wait(Os::Mutex& mutex);
118 
124  void notify() override;
125 
131  void notifyAll() override;
132 
136 
137  private:
139  Os::Mutex* m_lock = nullptr;
140 
141  // This section is used to store the implementation-defined file handle. To Os::File and fprime, this type is
142  // opaque and thus normal allocation cannot be done. Instead, we allow the implementor to store then handle in
143  // the byte-array here and set `handle` to that address for storage.
144  alignas(FW_HANDLE_ALIGNMENT)
145  ConditionVariableHandleStorage m_handle_storage;
146  ConditionVariableInterface& m_delegate;
147 };
148 } // namespace Os
149 #endif // OS_CONDITION_HPP_
void notify() override
notify a single waiter on this condition variable
Definition: Condition.cpp:23
ConditionVariableInterface()=default
Default constructor.
virtual Status pend(Os::Mutex &mutex)=0
wait on a condition variable
void notifyAll() override
notify all waiters on this condition variable
Definition: Condition.cpp:27
ConditionVariableHandle * getHandle() override
return the underlying condition variable handle (implementation specific). Delegates to implementatio...
Definition: Condition.cpp:32
~ConditionVariable() final
default virtual destructor
Definition: Condition.cpp:7
virtual void notifyAll()=0
notify all waiters on this condition variable
U8 ConditionVariableHandleStorage[FW_CONDITION_VARIABLE_HANDLE_MAX_SIZE]
Definition: Os.hpp:17
virtual ~ConditionVariableInterface()=default
Default destructor.
When trying to wait but we don't hold the mutex.
Definition: Condition.hpp:24
virtual ConditionVariableHandle * getHandle()=0
return the underlying condition variable handle (implementation specific).
virtual ConditionVariableInterface & operator=(const ConditionVariableInterface &other)=delete
assignment operator is forbidden
interface for condition variables
Definition: Condition.hpp:20
ConditionVariableInterface & operator=(const ConditionVariableInterface &other) override=delete
assignment operator is forbidden
ConditionVariable()
default constructor
Definition: Condition.cpp:5
static ConditionVariableInterface * getDelegate(ConditionVariableHandleStorage &aligned_new_memory)
provide a pointer to a Mutex delegate object
virtual void notify()=0
notify a single waiter on this condition variable
When trying to use a different mutex than expected mutex.
Definition: Condition.hpp:25
void wait(Os::Mutex &mutex)
wait on a condition variable
Definition: Condition.cpp:19
Condition variable handle parent.
Definition: Condition.hpp:14
Status pend(Os::Mutex &mutex) override
wait on a condition variable
Definition: Condition.cpp:11
#define FW_HANDLE_ALIGNMENT
Alignment of handle storage.
Definition: FpConfig.h:440
condition variable implementation
Definition: Condition.hpp:75
Operation was successful.
Definition: Condition.hpp:23
When trying to use a feature that isn't implemented.
Definition: Condition.hpp:26