FreeRTOScpp
|
Class to hold a block based lock. More...
#include <Lock.h>
Public Member Functions | |
Lock (Lockable &mylockable, bool mylocked=true, TickType_t wait=portMAX_DELAY) | |
Constructor. | |
Lock (Lockable &mylockable, TickType_t wait) | |
Constructor with assumed locking by specifying lock time. | |
virtual | ~Lock () |
Destructor. | |
bool | lock (TickType_t wait=portMAX_DELAY) |
Try to take to lock. | |
bool | locked () const |
Do we have the lock? | |
void | unlock () |
Release a lock. | |
Private Member Functions | |
Lock (Lock const &)=delete | |
We are not copyable. | |
void | operator= (Lock const &)=delete |
We are not assignable. | |
Private Attributes | |
Lockable & | lockable |
The Lockage object we are connected to. | |
int | lockCnt |
The number of locks we hold on lockable. | |
Class to hold a block based lock.
(auto unlocks on in its destructor)
Typical calling sequences:
then, in a block
or
or
Lock::Lock | ( | Lockable & | mylockable, |
bool | mylocked = true, | ||
TickType_t | wait = portMAX_DELAY ) |
Constructor.
This is the most generic constructor, and the one that will be used if no parameters beyond the lockable object are given. The alternate constructor only take the time to wait, and assumes the second parameter is true
If wait is specified (or some code might abort the wait) then the code should check with a call to locked() to confirm the lock has been taken.
mylockable | The Lockable object we will be using |
mylocked | Should we start by taking the lock |
wait | How long to wait to take the lock |
References lock().
|
inline |
Constructor with assumed locking by specifying lock time.
mylockable | The Lockabe object to use |
wait | The time it Ticks to wait to get the lock. |
|
virtual |
Destructor.
References Lockable::give(), lockable, and lockCnt.
|
privatedelete |
We are not copyable.
bool Lock::lock | ( | TickType_t | wait = portMAX_DELAY | ) |
Try to take to lock.
Note, lock allows for nested calls, which need to be unlocked as many times as taken, even if the lockable isn't recursive.
wait | How long to wait in Ticks |
References lockable, lockCnt, and Lockable::take().
Referenced by Lock().
|
inline |
Do we have the lock?
|
privatedelete |
We are not assignable.
void Lock::unlock | ( | ) |
Release a lock.
References Lockable::give(), lockable, and lockCnt.
|
private |
|
private |