|
Open Model Railroad Network (OpenMRN)
|
A synchronization primitive for device drivers, where execution has to happen in an interrupt context and on regular contexts. More...
#include <BlockOrWakeUp.hxx>
Classes | |
| struct | CriticalHolder |
| RAII class for holding a critical section lock. More... | |
| struct | LockHolder |
| RAII class for holding a mutex lock that can be upgraded to a critical section lock. More... | |
Public Member Functions | |
| template<class T > | |
| BlockOrWakeUp (const T &t) | |
| Constructor. | |
| LockHolder | holder () |
| Acquires a lock (not critical) and returns an RAII holder object. | |
| void | notify_from_isr () |
| Called from ISR context to wake up a regular context or a caller waiting. | |
| Notifiable * | register_notifiable (Notifiable *n) |
| Sets the notifiable that will be called from the ISR (or regular) context when there is more data to consume or space to fill with data. | |
Private Member Functions | |
| void | single_lock () |
| Locks the mutex (not the critical). | |
| void | single_unlock () |
| Unlocks the mutex (not the critical). | |
Private Attributes | |
| OSMutex | m_ |
| Mutex holding non-criticla lock. | |
| OSSem | s_ |
| Semaphore used to wake up callers. | |
| Notifiable * | notifiable_ |
| Notifiable to be woken up when an ISR event happens. | |
Friends | |
| class | LockHolder |
| class | CriticalHolder |
A synchronization primitive for device drivers, where execution has to happen in an interrupt context and on regular contexts.
Helpful to implement read() and write() calls contending for a single hardware instance / ring buffer queueing inbound and outbound data. Supports the following features:
Critical should be an object (possibly with no member variables for zero size) that has the following functions:
In some cases, Atomic is a good candidate for Critical.
Definition at line 65 of file BlockOrWakeUp.hxx.
|
inline |
Constructor.
| t | constructor argument to the underlying Critical object. |
Definition at line 72 of file BlockOrWakeUp.hxx.
|
inline |
Acquires a lock (not critical) and returns an RAII holder object.
The lock can then be upgraded to critical as needed.
Definition at line 182 of file BlockOrWakeUp.hxx.
|
inline |
Called from ISR context to wake up a regular context or a caller waiting.
Definition at line 188 of file BlockOrWakeUp.hxx.
|
inline |
Sets the notifiable that will be called from the ISR (or regular) context when there is more data to consume or space to fill with data.
| n | is the notifiable to be called. |
Definition at line 205 of file BlockOrWakeUp.hxx.
|
inlineprivate |
Locks the mutex (not the critical).
Definition at line 214 of file BlockOrWakeUp.hxx.
|
inlineprivate |
Unlocks the mutex (not the critical).
Definition at line 219 of file BlockOrWakeUp.hxx.
|
friend |
Definition at line 81 of file BlockOrWakeUp.hxx.
|
friend |
Definition at line 80 of file BlockOrWakeUp.hxx.
|
private |
Mutex holding non-criticla lock.
Definition at line 225 of file BlockOrWakeUp.hxx.
|
private |
Notifiable to be woken up when an ISR event happens.
Definition at line 229 of file BlockOrWakeUp.hxx.
|
private |
Semaphore used to wake up callers.
Definition at line 227 of file BlockOrWakeUp.hxx.