F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
ConditionVariableInterface.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title Os/ConditionVariableInterface.hpp
3 // \brief Os::ConditionVariableHandle and Os::ConditionVariableInterface definitions
4 // ======================================================================
5 #ifndef OS_CONDITIONVARIABLEINTERFACE_HPP_
6 #define OS_CONDITIONVARIABLEINTERFACE_HPP_
7 
8 #include <type_traits>
9 
10 #include "Fw/Types/Assert.hpp"
11 #include "Os/Mutex.hpp"
12 #include "Os/Os.hpp"
13 #include "config/OsSelection.hpp" // defines Os::ConditionVariable alias and OS_CONDITION_VARIABLE_HEADER consumed by Os/Condition.hpp; do not remove
14 
15 namespace Os {
16 
17 class DelegateMutex;
18 class DelegateConditionVariable;
19 
20 // A condition variable implementation operates on the handle of the configured Os::Mutex. Selecting a
21 // compile-time Mutex while leaving Os::ConditionVariable on the link-time delegate (or vice versa) hands the
22 // CMake-chosen implementation a handle of the wrong type, so both must be delegates or neither may be.
23 static_assert(std::is_same<Os::Mutex, Os::DelegateMutex>::value ==
24  std::is_same<Os::ConditionVariable, Os::DelegateConditionVariable>::value,
25  "Os::Mutex and Os::ConditionVariable must be overridden together in config/OsSelection.hpp");
26 
29 
35  public:
36  enum Status {
43  };
44 
46  ConditionVariableInterface() = default;
48  virtual ~ConditionVariableInterface() = default;
49 
52 
54  virtual ConditionVariableInterface& operator=(const ConditionVariableInterface& other) = delete;
55 
64  virtual Status pend(Os::Mutex& mutex) = 0;
65 
70  virtual void notify() = 0;
71 
76  virtual void notifyAll() = 0;
77 
80  virtual ConditionVariableHandle* getHandle() = 0;
81 
88 
89  // ------------------------------------------------------------------
90  // Common (non-virtual) functions built on top of pend(). Defined inline
91  // on the interface so they are available regardless of which
92  // implementation Os::ConditionVariable is configured to be.
93  // ------------------------------------------------------------------
94 
106  void wait(Os::Mutex& mutex) {
107  const Status status = this->pend(mutex);
108  FW_ASSERT(status == Status::OP_OK,
109  static_cast<FwAssertArgType>(reinterpret_cast<PlatformPointerCastType>(this)), status);
110  }
111 };
112 
113 } // namespace Os
114 
115 #endif // OS_CONDITIONVARIABLEINTERFACE_HPP_
ConditionVariable does not support operation.
ConditionVariableInterface()=default
Default constructor.
Operation succeeded.
Definition: Os.hpp:27
virtual Status pend(Os::Mutex &mutex)=0
wait on a condition variable
Link-time delegating Mutex implementation.
virtual void notifyAll()=0
notify all waiters on this condition variable
U8 ConditionVariableHandleStorage[FW_CONDITION_VARIABLE_HANDLE_MAX_SIZE]
Definition: Os.hpp:18
virtual ~ConditionVariableInterface()=default
Default destructor.
When trying to wait but we don&#39;t hold the mutex.
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
static ConditionVariableInterface * getDelegate(ConditionVariableHandleStorage &aligned_new_memory)
provide a pointer to a ConditionVariable delegate object
virtual void notify()=0
notify a single waiter on this condition variable
When trying to use a different mutex than expected mutex.
Condition variable handle parent.
void wait(Os::Mutex &mutex)
wait on a condition variable and assert success
#define FW_ASSERT(...)
Definition: Assert.hpp:14
When trying to use a feature that isn&#39;t implemented.