@@ -19,6 +19,14 @@ class ConditionVariableHandle {};
1919// ! reacquiring the mutex once the condition has been notified.
2020class ConditionVariableInterface {
2121 public:
22+ enum Status {
23+ OP_OK, // !< Operation was successful
24+ ERROR_MUTEX_NOT_HELD, // !< When trying to wait but we don't hold the mutex
25+ ERROR_DIFFERENT_MUTEX, // !< When trying to use a different mutex than expected mutex
26+ ERROR_NOT_IMPLEMENTED, // !< When trying to use a feature that isn't implemented
27+ ERROR_OTHER // !< All other errors
28+ };
29+
2230 // ! Default constructor
2331 ConditionVariableInterface () = default ;
2432 // ! Default destructor
@@ -37,7 +45,8 @@ class ConditionVariableInterface {
3745 // ! thread of execution.
3846 // !
3947 // ! \param mutex: mutex to unlock as part of this operation
40- virtual void wait (Os::Mutex& mutex) = 0;
48+ // ! \return status of the conditional wait
49+ virtual Status pend (Os::Mutex& mutex) = 0;
4150
4251 // ! \brief notify a single waiter on this condition variable
4352 // !
@@ -88,10 +97,24 @@ class ConditionVariable final : public ConditionVariableInterface {
8897 // !
8998 // ! \warning it is invalid to supply a mutex different from those supplied by others
9099 // ! \warning conditions *must* be rechecked after the condition variable unlocks
91- // ! \note unlocked mutexes will be locked before waiting and will be relocked before this function returns
100+ // ! \warning the mutex must be locked by the calling task
101+ // !
102+ // ! \param mutex: mutex to unlock as part of this operation
103+ // ! \return status of the conditional wait
104+ Status pend (Os::Mutex& mutex) override ;
105+
106+ // ! \brief wait on a condition variable
107+ // !
108+ // ! Wait on a condition variable. This function will atomically unlock the provided mutex and block on the condition
109+ // ! in one step. Blocking will occur until a future `notify` or `notifyAll` call is made to this variable on another
110+ // ! thread of execution. This function delegates to the underlying implementation.
111+ // !
112+ // ! \warning it is invalid to supply a mutex different from those supplied by others
113+ // ! \warning conditions *must* be rechecked after the condition variable unlocks
114+ // ! \warning the mutex must be locked by the calling task
92115 // !
93116 // ! \param mutex: mutex to unlock as part of this operation
94- void wait (Os::Mutex& mutex) override ;
117+ void wait (Os::Mutex& mutex);
95118
96119 // ! \brief notify a single waiter on this condition variable
97120 // !
@@ -118,8 +141,9 @@ class ConditionVariable final : public ConditionVariableInterface {
118141 // This section is used to store the implementation-defined file handle. To Os::File and fprime, this type is
119142 // opaque and thus normal allocation cannot be done. Instead, we allow the implementor to store then handle in
120143 // the byte-array here and set `handle` to that address for storage.
121- alignas (FW_HANDLE_ALIGNMENT) ConditionVariableHandleStorage m_handle_storage; // !< Storage for aligned FileHandle data
122- ConditionVariableInterface& m_delegate; // !< Delegate for the real implementation
144+ alignas (FW_HANDLE_ALIGNMENT)
145+ ConditionVariableHandleStorage m_handle_storage; // !< Storage for aligned FileHandle data
146+ ConditionVariableInterface& m_delegate; // !< Delegate for the real implementation
123147};
124- }
125- #endif // OS_CONDITION_HPP_
148+ } // namespace Os
149+ #endif // OS_CONDITION_HPP_
0 commit comments