FreeRTOScpp
FreeRTOScpp::ReadWriteLock Class Reference

Read/Write Lock control. More...

#include <ReadWrite.h>

Inheritance diagram for FreeRTOScpp::ReadWriteLock:
Collaboration diagram for FreeRTOScpp::ReadWriteLock:

Public Member Functions

 ReadWriteLock ()
 
 ~ReadWriteLock ()
 
bool give () override
 
bool give () override
 
bool readLock (TickType_t wait=portMAX_DELAY)
 ReadLock. More...
 
bool readLock (Time_ms delay_ms)
 
bool readUnlock ()
 Remove our lock. More...
 
bool releaseReserved ()
 If we have a reserved lock, down grade to just a read lock. More...
 
bool requestReserved ()
 Task with a Read Lock request upgrade to a reserved lock. More...
 
bool reservedLock (TickType_t wait=portMAX_DELAY)
 Get an upgradable Read Lock. More...
 
bool reservedLock (Time_ms delay_ms)
 
Readerrlock ()
 Get Read Lockable. More...
 
bool take (TickType_t wait) override
 
bool take (Time_ms ms)
 
bool take (Time_ms ms)
 
bool take (TickType_t wait) override
 
Writerwlock ()
 Get Write Lockable. More...
 
bool writeLock (TickType_t wait=portMAX_DELAY)
 Take the write lock, requires readCount to be 0, or 1 if we reserved the upgrade. More...
 
bool writeLock (Time_ms delay_ms)
 
bool writeUnlock ()
 Release the write lock. More...
 

Protected Attributes

EventGroup event
 
int readCount = 0
 Count of Read Locks. More...
 
TaskHandle_t reserved = nullptr
 Reserved Lock indicator. More...
 
int writeReq = -1
 Write Request Pending Priority. More...
 

Detailed Description

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

Constructor & Destructor Documentation

◆ ReadWriteLock()

FreeRTOScpp::ReadWriteLock::ReadWriteLock ( )

◆ ~ReadWriteLock()

FreeRTOScpp::ReadWriteLock::~ReadWriteLock ( )

Member Function Documentation

◆ give() [1/2]

bool FreeRTOScpp::Reader::give ( )
overridevirtualinherited

Implements FreeRTOScpp::Lockable.

Referenced by FreeRTOScpp::Reader::Reader(), and FreeRTOScpp::Writer::Writer().

Here is the caller graph for this function:

◆ give() [2/2]

bool FreeRTOScpp::Writer::give ( )
overridevirtualinherited

Implements FreeRTOScpp::Lockable.

◆ readLock() [1/2]

bool FreeRTOScpp::ReadWriteLock::readLock ( TickType_t  wait = portMAX_DELAY)

ReadLock.

Get a read lock.

Parameters
waitThe 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:
      • return false
    • else wait a tick for read_bit event.

◆ readLock() [2/2]

bool FreeRTOScpp::ReadWriteLock::readLock ( Time_ms  delay_ms)
inline

References FreeRTOScpp::ms2ticks(), and readLock().

Referenced by readLock().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ readUnlock()

bool FreeRTOScpp::ReadWriteLock::readUnlock ( )

Remove our lock.

If we reserved the upgrade, release that.

◆ releaseReserved()

bool FreeRTOScpp::ReadWriteLock::releaseReserved ( )

If we have a reserved lock, down grade to just a read lock.

◆ requestReserved()

bool FreeRTOScpp::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() [1/2]

bool FreeRTOScpp::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

◆ reservedLock() [2/2]

bool FreeRTOScpp::ReadWriteLock::reservedLock ( Time_ms  delay_ms)
inline

References FreeRTOScpp::ms2ticks(), and reservedLock().

Referenced by reservedLock().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rlock()

Reader& FreeRTOScpp::ReadWriteLock::rlock ( )
inline

Get Read Lockable.

Returns
a lockable object for using with Read Locks.

◆ take() [1/4]

bool FreeRTOScpp::Reader::take ( TickType_t  wait)
overridevirtualinherited

Implements FreeRTOScpp::Lockable.

Referenced by FreeRTOScpp::Reader::Reader(), and FreeRTOScpp::Writer::Writer().

Here is the caller graph for this function:

◆ take() [2/4]

bool FreeRTOScpp::Lockable::take ( Time_ms  ms)
inlineinherited

References FreeRTOScpp::Lockable::give(), FreeRTOScpp::Lockable::Lockable(), FreeRTOScpp::ms2ticks(), FreeRTOScpp::Lockable::operator=(), and FreeRTOScpp::Lockable::take().

Referenced by FreeRTOScpp::Lockable::take().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ take() [3/4]

bool FreeRTOScpp::Lockable::take ( Time_ms  ms)
inlineinherited

References FreeRTOScpp::Lockable::give(), FreeRTOScpp::Lockable::Lockable(), FreeRTOScpp::ms2ticks(), FreeRTOScpp::Lockable::operator=(), and FreeRTOScpp::Lockable::take().

Referenced by FreeRTOScpp::Lockable::take().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ take() [4/4]

bool FreeRTOScpp::Writer::take ( TickType_t  wait)
overridevirtualinherited

Implements FreeRTOScpp::Lockable.

◆ wlock()

Writer& FreeRTOScpp::ReadWriteLock::wlock ( )
inline

Get Write Lockable.

Returns
a lockable object for using with Write Locks

◆ writeLock() [1/2]

bool FreeRTOScpp::ReadWriteLock::writeLock ( TickType_t  wait = portMAX_DELAY)

Take the write lock, requires readCount to be 0, or 1 if we reserved the upgrade.

◆ writeLock() [2/2]

bool FreeRTOScpp::ReadWriteLock::writeLock ( Time_ms  delay_ms)
inline

References FreeRTOScpp::ms2ticks(), and writeLock().

Referenced by writeLock().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeUnlock()

bool FreeRTOScpp::ReadWriteLock::writeUnlock ( )

Release the write lock.

If we upgraded go back to a reserved lock which will need to be unlocked.

Member Data Documentation

◆ event

EventGroup FreeRTOScpp::ReadWriteLock::event
protected

◆ readCount

int FreeRTOScpp::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 FreeRTOScpp::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 FreeRTOScpp::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: