template<typename TWaitOp = stdext::inplace_function<void()>, typename TNotifyOp = stdext::inplace_function<void()>>
class embutil::InterruptCondition< TWaitOp, TNotifyOp >
Generic interrupt condition concept.
Provides a condition-variable class for use on an embedded system which does not have threading, but wants to use interrupts for notifications (e.g. with ARM's WFI instruction). ` If we think about interrupt and non-interrupt execution modes as two threads, locking in a non-interrupt thread is equivalent to disabling interrupts; waiting for condition variable to be notified is the equivalent for waiting for interrupts.
Clients supply one or two operations:
- wait(), which puts the processor in a mode to wait for interrupts (e.g.,
wfi)
- notify(), which pulls the processor out of the wait mode
- Note
- Some scenarios, like
wfi, do not require a function to be called. Instead, the wfi state exit is equivalent to notify(). Clients do not need to supply the notify operation in such scenarios.
This class is designed to be used with an InterruptLock.
- Template Parameters
-
| TWaitOp | Represents the storage type (std::function, stdext::inplace_function) and prototype for the wait operation. |
| TNotifyOp | Represents the storage type (std::function, stdext::inplace_function) and prototype for the notify operation. |
template<typename TWaitOp = stdext::inplace_function<void()>, typename TNotifyOp = stdext::inplace_function<void()>>
template<typename TWaitOp = stdext::inplace_function<void()>, typename TNotifyOp = stdext::inplace_function<void()>>
template<typename TLock >
Initiate a wait state.
Receives the reference to lockable object (has lock() and unlock() member functions) that is already locked.
The behavior of this function matches std::condition_variable:
- locked lock is received
- unlock the lock
- wait for notification to wake up
- re-acquire the lock and return control to the caller
This function is marked noexcept because we want the program to terminate if an exception results from this call. We don't actually know whether lock/unlock/wait_ can throw.
- Template Parameters
-
| TLock | the type of the lock. The compiler deduces this template parameter. |
- Parameters
-
- Precondition
- lock is already locked.
- Postcondition
- lock is locked.
References embutil::InterruptCondition< TWaitOp, TNotifyOp >::wait_.