Read/Write Lock control.
More...
#include <ReadWrite.h>
Read/Write Lock control.
States:
- Free: readCount == 0
- Read: readCount > 0, reserved == 0
- Reserved: readCount > 0, reserved != 0
- Write: readCount == -1, reserved == 0
- Upgraded: readCount == -1, reserved != 0
- Warning
- This is a fairly new module, and may not be fully tested
◆ ReadWriteLock()
ReadWriteLock::ReadWriteLock |
( |
| ) |
|
◆ ~ReadWriteLock()
ReadWriteLock::~ReadWriteLock |
( |
| ) |
|
◆ give() [1/2]
◆ give() [2/2]
◆ readLock()
bool ReadWriteLock::readLock |
( |
TickType_t | wait = portMAX_DELAY | ) |
|
ReadLock.
Get a read lock.
- Parameters
-
wait | The maximum number of ticks to wait to get the lock |
- Returns
- true if the read lock has been granted
Algorithm:
- Loop
- If readCount >=0 and our priority > writeReq
- Increment readCount
- return true
- if Time has expired:
- else wait a tick for read_bit event.
References read_bit.
◆ readUnlock()
bool ReadWriteLock::readUnlock |
( |
| ) |
|
Remove our lock.
If we reserved the upgrade, release that.
References read_bit, and write_bit.
◆ releaseReserved()
bool ReadWriteLock::releaseReserved |
( |
| ) |
|
If we have a reserved lock, down grade to just a read lock.
References read_bit.
◆ requestReserved()
bool ReadWriteLock::requestReserved |
( |
| ) |
|
Task with a Read Lock request upgrade to a reserved lock.
If no reservation current, will be granted, if reservation present, will be rejected.
Does not check if this task has a read lock, but that is assumed.
◆ reservedLock()
bool ReadWriteLock::reservedLock |
( |
TickType_t | wait = portMAX_DELAY | ) |
|
Get an upgradable Read Lock.
like readLock, but add reserved == nullptr to the conditions. On success will set reserved to our task handle.
Only one task can reserve this, as if two are in this state they will deadlock when they both try to upgrade
References read_bit.
◆ rlock()
Reader & ReadWriteLock::rlock |
( |
| ) |
|
|
inline |
Get Read Lockable.
- Returns
- a lockable object for using with Read Locks.
◆ take() [1/2]
bool Reader::take |
( |
TickType_t | wait | ) |
|
|
overridevirtualinherited |
◆ take() [2/2]
bool Writer::take |
( |
TickType_t | wait | ) |
|
|
overridevirtualinherited |
◆ wlock()
Writer & ReadWriteLock::wlock |
( |
| ) |
|
|
inline |
Get Write Lockable.
- Returns
- a lockable object for using with Write Locks
◆ writeLock()
bool ReadWriteLock::writeLock |
( |
TickType_t | wait = portMAX_DELAY | ) |
|
Take the write lock, requires readCount to be 0, or 1 if we reserved the upgrade.
References read_bit, and write_bit.
◆ writeUnlock()
bool ReadWriteLock::writeUnlock |
( |
| ) |
|
Release the write lock.
If we upgraded go back to a reserved lock which will need to be unlocked.
References read_bit, and write_bit.
◆ event
◆ readCount
int ReadWriteLock::readCount = 0 |
|
protected |
Count of Read Locks.
If 0, then lock is free if >0, lock is in read mode and is the count of the number of read locks granted if <0, loci is in write mode.
◆ reserved
TaskHandle_t ReadWriteLock::reserved = nullptr |
|
protected |
Reserved Lock indicator.
If nullptr, then no reservedLock are currently in existence, so a reservedLock can be granted
Else, TaskHandle of the task that has reserved the right to upgrade to a write lock.
◆ writeReq
int ReadWriteLock::writeReq = -1 |
|
protected |
Write Request Pending Priority.
If in Read mode, and a task with priority below writeReq
The documentation for this class was generated from the following files: