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 {
29  };
30 
32  ConditionVariableInterface() = default;
34  virtual ~ConditionVariableInterface() = default;
35 
38 
40  virtual ConditionVariableInterface& operator=(const ConditionVariableInterface& other) = delete;
41 
50  virtual Status pend(Os::Mutex& mutex) = 0;
51 
56  virtual void notify() = 0;
57 
62  virtual void notifyAll() = 0;
63 
66  virtual ConditionVariableHandle* getHandle() = 0;
67 
70 };
71 
77  public:
80 
82  ~ConditionVariable() final;
83 
85  ConditionVariable(const ConditionVariableInterface& other) = delete;
86 
88  ConditionVariable(const ConditionVariableInterface* other) = delete;
89 
91  ConditionVariableInterface& operator=(const ConditionVariableInterface& other) override = delete;
92 
105  Status pend(Os::Mutex& mutex) override;
106 
118  void wait(Os::Mutex& mutex);
119 
125  void notify() override;
126 
132  void notifyAll() override;
133 
137 
138  private:
140  Os::Mutex* m_lock = nullptr;
141 
142  // This section is used to store the implementation-defined file handle. To Os::File and fprime, this type is
143  // opaque and thus normal allocation cannot be done. Instead, we allow the implementor to store then handle in
144  // the byte-array here and set `handle` to that address for storage.
145  alignas(FW_HANDLE_ALIGNMENT)
146  ConditionVariableHandleStorage m_handle_storage;
147  ConditionVariableInterface& m_delegate;
148 };
149 } // namespace Os
150 #endif // OS_CONDITION_HPP_
void notify() override
notify a single waiter on this condition variable
Definition: Condition.cpp:23
ConditionVariable does not support operation.
Definition: Condition.hpp:27
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:76
Operation was successful.
Definition: Condition.hpp:23
When trying to use a feature that isn't implemented.
Definition: Condition.hpp:26