distortos  v0.7.0
object-oriented C++ RTOS for microcontrollers
distortos::internal::MutexControlBlock Class Reference

MutexControlBlock class is a control block for Mutex. More...

#include "distortos/internal/synchronization/MutexControlBlock.hpp"

Inheritance diagram for distortos::internal::MutexControlBlock:
[legend]
Collaboration diagram for distortos::internal::MutexControlBlock:
[legend]

Public Types

using Protocol = MutexProtocol
 mutex protocols More...
 
using RecursiveLocksCount = uint16_t
 type used for counting recursive locks More...
 
using Type = MutexType
 type of mutex More...
 

Public Member Functions

uint8_t getBoostedPriority () const
 Gets "boosted priority" of the mutex. More...
 
ThreadControlBlockgetOwner () const
 
- Public Member Functions inherited from distortos::internal::MutexListNode
constexpr MutexListNode ()
 MutexListNode's constructor. More...
 

Static Public Attributes

static constexpr uint8_t typeShift {0}
 shift of "type" subfield, bits More...
 
static constexpr uint8_t typeWidth {CHAR_BIT / 2}
 width of "type" subfield, bits More...
 
static constexpr uint8_t protocolShift {typeShift + typeWidth}
 shift of "protocol" subfield, bits More...
 
static constexpr uint8_t protocolWidth {CHAR_BIT / 2}
 width of "protocol" subfield, bits More...
 

Protected Member Functions

constexpr MutexControlBlock (const Type type, const Protocol protocol, const uint8_t priorityCeiling)
 MutexControlBlock's constructor. More...
 
int doBlock ()
 Blocks current thread, transferring it to blockedList_. More...
 
int doBlockUntil (TickClock::time_point timePoint)
 Blocks current thread with timeout, transferring it to blockedList_. More...
 
void doLock ()
 Performs actual locking of previously unlocked mutex. More...
 
void doUnlockOrTransferLock ()
 Performs unlocking or transfer of lock from current owner to next thread on the list. More...
 
uint8_t getPriorityCeiling () const
 
Protocol getProtocol () const
 
RecursiveLocksCountgetRecursiveLocksCount ()
 
Type getType () const
 

Private Member Functions

void beforeBlock () const
 Performs any actions required before actually blocking on the mutex. More...
 
void doTransferLock ()
 Performs transfer of lock from current owner to next thread on the list. More...
 
void doUnlock ()
 Performs actual unlocking of previously locked mutex. More...
 

Private Attributes

ThreadList blockedList_
 ThreadControlBlock objects blocked on mutex. More...
 
ThreadControlBlockowner_
 owner of the mutex More...
 
RecursiveLocksCount recursiveLocksCount_
 number of recursive locks, used when mutex type is recursive More...
 
uint8_t priorityCeiling_
 priority ceiling of mutex, valid only when protocol_ == Protocol::priorityProtect More...
 
uint8_t typeProtocol_
 type of mutex and its protocol More...
 

Additional Inherited Members

- Public Attributes inherited from distortos::internal::MutexListNode
estd::IntrusiveListNode node
 node for intrusive list More...
 

Detailed Description

MutexControlBlock class is a control block for Mutex.

Member Typedef Documentation

◆ Protocol

◆ RecursiveLocksCount

type used for counting recursive locks

◆ Type

Constructor & Destructor Documentation

◆ MutexControlBlock()

constexpr distortos::internal::MutexControlBlock::MutexControlBlock ( const Type  type,
const Protocol  protocol,
const uint8_t  priorityCeiling 
)
inlineprotected

MutexControlBlock's constructor.

Parameters
[in]typeis the type of mutex
[in]protocolis the mutex protocol
[in]priorityCeilingis the priority ceiling of mutex, ignored when protocol != Protocol::priorityProtect

Member Function Documentation

◆ beforeBlock()

void distortos::internal::MutexControlBlock::beforeBlock ( ) const
private

Performs any actions required before actually blocking on the mutex.

In case of priorityInheritance protocol, priority of owner thread is boosted and this mutex is set as the blocking mutex of the calling thread. In all other cases this function does nothing.

Attention
must be called in block() and blockUntil() before actually blocking of the calling thread.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ doBlock()

int distortos::internal::MutexControlBlock::doBlock ( )
protected

Blocks current thread, transferring it to blockedList_.

Returns
0 on success, error code otherwise:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ doBlockUntil()

int distortos::internal::MutexControlBlock::doBlockUntil ( TickClock::time_point  timePoint)
protected

Blocks current thread with timeout, transferring it to blockedList_.

Parameters
[in]timePointis the time point at which the thread will be unblocked (if not already unblocked)
Returns
0 on success, error code otherwise:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ doLock()

void distortos::internal::MutexControlBlock::doLock ( )
protected

Performs actual locking of previously unlocked mutex.

Attention
mutex must be unlocked
Here is the call graph for this function:
Here is the caller graph for this function:

◆ doTransferLock()

void distortos::internal::MutexControlBlock::doTransferLock ( )
private

Performs transfer of lock from current owner to next thread on the list.

Attention
mutex must be locked and blockedList_ must not be empty
Here is the call graph for this function:
Here is the caller graph for this function:

◆ doUnlock()

void distortos::internal::MutexControlBlock::doUnlock ( )
private

Performs actual unlocking of previously locked mutex.

Attention
mutex must be locked and blockedList_ must be empty
Here is the call graph for this function:
Here is the caller graph for this function:

◆ doUnlockOrTransferLock()

void distortos::internal::MutexControlBlock::doUnlockOrTransferLock ( )
protected

Performs unlocking or transfer of lock from current owner to next thread on the list.

Mutex is unlocked if blockedList_ is empty, otherwise the ownership is transferred to the next thread.

Attention
mutex must be locked
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getBoostedPriority()

uint8_t distortos::internal::MutexControlBlock::getBoostedPriority ( ) const

Gets "boosted priority" of the mutex.

"Boosted priority" of the mutex depends on the selected priority protocol:

  • none - 0,
  • priorityInheritance - effective priority of the highest priority thread blocked on this mutex or 0 if no threads are blocked,
  • priorityProtect - priority ceiling.
Returns
"boosted priority" of the mutex
Here is the call graph for this function:

◆ getOwner()

ThreadControlBlock* distortos::internal::MutexControlBlock::getOwner ( ) const
inline
Returns
owner of the mutex, nullptr if mutex is currently unlocked
Here is the caller graph for this function:

◆ getPriorityCeiling()

uint8_t distortos::internal::MutexControlBlock::getPriorityCeiling ( ) const
inlineprotected
Returns
priority ceiling of mutex, valid only when protocol_ == Protocol::priorityProtect
Here is the caller graph for this function:

◆ getProtocol()

Protocol distortos::internal::MutexControlBlock::getProtocol ( ) const
inlineprotected
Returns
mutex protocol
Here is the caller graph for this function:

◆ getRecursiveLocksCount()

RecursiveLocksCount& distortos::internal::MutexControlBlock::getRecursiveLocksCount ( )
inlineprotected
Returns
reference to number of recursive locks
Here is the caller graph for this function:

◆ getType()

Type distortos::internal::MutexControlBlock::getType ( ) const
inlineprotected
Returns
type of mutex
Here is the caller graph for this function:

Member Data Documentation

◆ blockedList_

ThreadList distortos::internal::MutexControlBlock::blockedList_
private

ThreadControlBlock objects blocked on mutex.

◆ owner_

ThreadControlBlock* distortos::internal::MutexControlBlock::owner_
private

owner of the mutex

◆ priorityCeiling_

uint8_t distortos::internal::MutexControlBlock::priorityCeiling_
private

priority ceiling of mutex, valid only when protocol_ == Protocol::priorityProtect

◆ protocolShift

constexpr uint8_t distortos::internal::MutexControlBlock::protocolShift {typeShift + typeWidth}
static

shift of "protocol" subfield, bits

◆ protocolWidth

constexpr uint8_t distortos::internal::MutexControlBlock::protocolWidth {CHAR_BIT / 2}
static

width of "protocol" subfield, bits

◆ recursiveLocksCount_

RecursiveLocksCount distortos::internal::MutexControlBlock::recursiveLocksCount_
private

number of recursive locks, used when mutex type is recursive

◆ typeProtocol_

uint8_t distortos::internal::MutexControlBlock::typeProtocol_
private

type of mutex and its protocol

◆ typeShift

constexpr uint8_t distortos::internal::MutexControlBlock::typeShift {0}
static

shift of "type" subfield, bits

◆ typeWidth

constexpr uint8_t distortos::internal::MutexControlBlock::typeWidth {CHAR_BIT / 2}
static

width of "type" subfield, bits


The documentation for this class was generated from the following files: