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

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

#include <MutexControlBlock.hpp>

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

Public Types

enum  Protocol : uint8_t { Protocol::none, Protocol::priorityInheritance, Protocol::priorityProtect }
 mutex protocols More...
 

Public Member Functions

constexpr MutexControlBlock (const Protocol protocol, const uint8_t priorityCeiling)
 MutexControlBlock constructor. More...
 
int block ()
 Blocks current thread, transferring it to blockedList_. More...
 
int blockUntil (TickClock::time_point timePoint)
 Blocks current thread with timeout, transferring it to blockedList_. More...
 
uint8_t getBoostedPriority () const
 Gets "boosted priority" of the mutex. More...
 
ThreadControlBlockgetOwner () const
 
uint8_t getPriorityCeiling () const
 
Protocol getProtocol () const
 
void lock ()
 Performs actual locking of previously unlocked mutex. More...
 
void unlockOrTransferLock ()
 Performs unlocking or transfer of lock from current owner to next thread on the list. More...
 
- Public Member Functions inherited from distortos::internal::MutexListNode
constexpr MutexListNode ()
 MutexListNode's constructor. More...
 

Private Member Functions

void priorityInheritanceBeforeBlock () const
 Performs action required for priority inheritance before actually blocking on the mutex. More...
 
void transferLock ()
 Performs transfer of lock from current owner to next thread on the list. More...
 
void unlock ()
 Performs actual unlocking of previously locked mutex. More...
 

Private Attributes

ThreadList blockedList_
 ThreadControlBlock objects blocked on mutex. More...
 
ThreadControlBlockowner_
 owner of the mutex More...
 
Protocol protocol_
 mutex protocol More...
 
uint8_t priorityCeiling_
 priority ceiling of mutex, valid only when protocol_ == Protocol::priorityProtect 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 Enumeration Documentation

◆ Protocol

mutex protocols

Enumerator
none 

no protocol, similar to PTHREAD_PRIO_NONE

priorityInheritance 

priority inheritance protocol, similar to PTHREAD_PRIO_INHERIT

priorityProtect 

priority protection protocol (Immediate Ceiling Priority Protocol), similar to PTHREAD_PRIO_PROTECT

Constructor & Destructor Documentation

◆ MutexControlBlock()

constexpr distortos::internal::MutexControlBlock::MutexControlBlock ( const Protocol  protocol,
const uint8_t  priorityCeiling 
)
inline

MutexControlBlock constructor.

Parameters
[in]protocolis the mutex protocol
[in]priorityCeilingis the priority ceiling of mutex, ignored when protocol != Protocol::priorityProtect
Here is the call graph for this function:

Member Function Documentation

◆ block()

int distortos::internal::MutexControlBlock::block ( )

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:

◆ blockUntil()

int distortos::internal::MutexControlBlock::blockUntil ( TickClock::time_point  timePoint)

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:

◆ 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 caller 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
inline
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
inline
Returns
mutex protocol
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lock()

void distortos::internal::MutexControlBlock::lock ( )

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:

◆ priorityInheritanceBeforeBlock()

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

Performs action required for priority inheritance before actually blocking on the mutex.

This must be called in block() and blockUntil() before actually blocking of the calling thread.

mutex's protocol must be PriorityInheritance

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

◆ transferLock()

void distortos::internal::MutexControlBlock::transferLock ( )
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:

◆ unlock()

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

Performs actual unlocking of previously locked mutex.

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

◆ unlockOrTransferLock()

void distortos::internal::MutexControlBlock::unlockOrTransferLock ( )

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 transfered to the next thread.

Attention
mutex must be locked
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

◆ protocol_

Protocol distortos::internal::MutexControlBlock::protocol_
private

mutex protocol


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