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

ThreadControlBlock class is a simple description of a Thread. More...

#include <ThreadControlBlock.hpp>

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

Classes

class  UnblockFunctor
 

Public Types

enum  UnblockReason : uint8_t { UnblockReason::unblockRequest, UnblockReason::timeout, UnblockReason::signal }
 reason of thread unblocking More...
 

Public Member Functions

 ThreadControlBlock (Stack &&stack, uint8_t priority, SchedulingPolicy schedulingPolicy, ThreadGroupControlBlock *threadGroupControlBlock, SignalsReceiver *signalsReceiver, Thread &owner)
 ThreadControlBlock constructor. More...
 
 ~ThreadControlBlock ()
 ThreadControlBlock's destructor. More...
 
int addHook ()
 Hook function executed when thread is added to scheduler. More...
 
void blockHook (const UnblockFunctor *const unblockFunctor)
 Block hook function of thread. More...
 
ThreadListgetList () const
 
MutexListgetOwnedProtocolMutexList ()
 
ThreadgetOwner () const
 
RoundRobinQuantumgetRoundRobinQuantum ()
 
SchedulingPolicy getSchedulingPolicy () const
 
SignalsReceiverControlBlockgetSignalsReceiverControlBlock () const
 
StackgetStack ()
 
const StackgetStack () const
 
ThreadState getState () const
 
void setList (ThreadList *const list)
 Sets the list that has this object. More...
 
void setPriority (uint8_t priority, bool alwaysBehind={})
 Changes priority of thread. More...
 
void setPriorityInheritanceMutexControlBlock (const MutexControlBlock *const priorityInheritanceMutexControlBlock)
 
void setSchedulingPolicy (SchedulingPolicy schedulingPolicy)
 
void setState (const ThreadState state)
 
void switchedToHook ()
 Hook function called when context is switched to this thread. More...
 
void unblockHook (UnblockReason unblockReason)
 Unblock hook function of thread. More...
 
void updateBoostedPriority (uint8_t boostedPriority={})
 Updates boosted priority of the thread. More...
 
 ThreadControlBlock (const ThreadControlBlock &)=delete
 
 ThreadControlBlock (ThreadControlBlock &&)=default
 
const ThreadControlBlockoperator= (const ThreadControlBlock &)=delete
 
ThreadControlBlockoperator= (ThreadControlBlock &&)=delete
 
- Public Member Functions inherited from distortos::internal::ThreadListNode
constexpr ThreadListNode (const uint8_t priority)
 ThreadListNode's constructor. More...
 
uint8_t getEffectivePriority () const
 
uint8_t getPriority () const
 

Private Member Functions

void reposition (bool loweringBefore)
 Repositions the thread on the list it's currently on. More...
 

Private Attributes

Stack stack_
 internal stack object More...
 
Threadowner_
 reference to Thread object that owns this ThreadControlBlock More...
 
MutexList ownedProtocolMutexList_
 list of mutexes (mutex control blocks) with enabled priority protocol owned by this thread More...
 
const MutexControlBlockpriorityInheritanceMutexControlBlock_
 pointer to MutexControlBlock (with PriorityInheritance protocol) that blocks this thread More...
 
ThreadListlist_
 pointer to list that has this object More...
 
ThreadGroupControlBlockthreadGroupControlBlock_
 pointer to ThreadGroupControlBlock with which this object is associated More...
 
const UnblockFunctorunblockFunctor_
 functor executed in unblockHook() More...
 
SignalsReceiverControlBlocksignalsReceiverControlBlock_
 pointer to SignalsReceiverControlBlock object for this thread, nullptr if this thread cannot receive signals More...
 
_reent reent_
 newlib's _reent structure with thread-specific data More...
 
RoundRobinQuantum roundRobinQuantum_
 round-robin quantum More...
 
SchedulingPolicy schedulingPolicy_
 scheduling policy of the thread More...
 
ThreadState state_
 current state of object More...
 

Additional Inherited Members

- Public Attributes inherited from distortos::internal::ThreadListNode
estd::IntrusiveListNode threadListNode
 node for intrusive list in thread lists More...
 
estd::IntrusiveListNode threadGroupNode
 node for intrusive list in thread group More...
 
- Protected Attributes inherited from distortos::internal::ThreadListNode
uint8_t priority_
 thread's priority, 0 - lowest, UINT8_MAX - highest More...
 
uint8_t boostedPriority_
 thread's boosted priority, 0 - no boosting More...
 

Detailed Description

ThreadControlBlock class is a simple description of a Thread.

Member Enumeration Documentation

◆ UnblockReason

reason of thread unblocking

Enumerator
unblockRequest 

explicit request to unblock the thread - normal unblock

timeout 

timeout - unblock via software timer

signal 

signal handler - unblock to deliver unmasked signal

Constructor & Destructor Documentation

◆ ThreadControlBlock()

distortos::internal::ThreadControlBlock::ThreadControlBlock ( internal::Stack &&  stack,
uint8_t  priority,
SchedulingPolicy  schedulingPolicy,
ThreadGroupControlBlock threadGroupControlBlock,
SignalsReceiver signalsReceiver,
Thread owner 
)

ThreadControlBlock constructor.

Parameters
[in]stackis an rvalue reference to Stack object which will be adopted for this thread
[in]priorityis the thread's priority, 0 - lowest, UINT8_MAX - highest
[in]schedulingPolicyis the scheduling policy of the thread
[in]threadGroupControlBlockis a pointer to ThreadGroupControlBlock to which this object will be added, nullptr to inherit thread group from currently running thread
[in]signalsReceiveris a pointer to SignalsReceiver object for this thread, nullptr to disable reception of signals for this thread
[in]owneris a reference to Thread object that owns this ThreadControlBlock
Here is the caller graph for this function:

◆ ~ThreadControlBlock()

distortos::internal::ThreadControlBlock::~ThreadControlBlock ( )

ThreadControlBlock's destructor.

Member Function Documentation

◆ addHook()

int distortos::internal::ThreadControlBlock::addHook ( )

Hook function executed when thread is added to scheduler.

If threadGroupControlBlock_ is nullptr, it is inherited from currently running thread. Then this object is added to the thread group (if it is valid).

Attention
This function should be called only by Scheduler::addInternal().
Returns
0 on success, error code otherwise:
  • EINVAL - inherited thread group is invalid;
Here is the call graph for this function:
Here is the caller graph for this function:

◆ blockHook()

void distortos::internal::ThreadControlBlock::blockHook ( const UnblockFunctor *const  unblockFunctor)
inline

Block hook function of thread.

Saves pointer to UnblockFunctor.

Attention
This function should be called only by Scheduler::blockInternal().
Parameters
[in]unblockFunctoris a pointer to UnblockFunctor which will be executed in unblockHook()

◆ getList()

ThreadList* distortos::internal::ThreadControlBlock::getList ( ) const
inline
Returns
pointer to list that has this object

◆ getOwnedProtocolMutexList()

MutexList& distortos::internal::ThreadControlBlock::getOwnedProtocolMutexList ( )
inline
Returns
reference to list of mutexes (mutex control blocks) with enabled priority protocol owned by this thread

◆ getOwner()

Thread& distortos::internal::ThreadControlBlock::getOwner ( ) const
inline
Returns
reference to Thread object that owns this ThreadControlBlock
Here is the caller graph for this function:

◆ getRoundRobinQuantum()

RoundRobinQuantum& distortos::internal::ThreadControlBlock::getRoundRobinQuantum ( )
inline
Returns
reference to internal RoundRobinQuantum object

◆ getSchedulingPolicy()

SchedulingPolicy distortos::internal::ThreadControlBlock::getSchedulingPolicy ( ) const
inline
Returns
scheduling policy of the thread
Here is the caller graph for this function:

◆ getSignalsReceiverControlBlock()

SignalsReceiverControlBlock* distortos::internal::ThreadControlBlock::getSignalsReceiverControlBlock ( ) const
inline
Returns
pointer to SignalsReceiverControlBlock object for this thread, nullptr if this thread cannot receive signals
Here is the caller graph for this function:

◆ getStack() [1/2]

Stack& distortos::internal::ThreadControlBlock::getStack ( )
inline
Returns
reference to internal Stack object
Here is the caller graph for this function:

◆ getStack() [2/2]

const Stack& distortos::internal::ThreadControlBlock::getStack ( ) const
inline
Returns
const reference to internal Stack object

◆ getState()

ThreadState distortos::internal::ThreadControlBlock::getState ( ) const
inline
Returns
current state of object
Here is the caller graph for this function:

◆ reposition()

void distortos::internal::ThreadControlBlock::reposition ( bool  loweringBefore)
private

Repositions the thread on the list it's currently on.

This function should be called when thread's effective priority changes.

Attention
list_ must not be nullptr
Parameters
[in]loweringBeforeselects the method of ordering when lowering the priority (it must be false when the priority is raised!):
  • true - the thread is moved to the head of the group of threads with the new priority, this is accomplished by temporarily boosting effective priority by 1,
  • false - the thread is moved to the tail of the group of threads with the new priority.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setList()

void distortos::internal::ThreadControlBlock::setList ( ThreadList *const  list)
inline

Sets the list that has this object.

Parameters
[in]listis a pointer to list that has this object
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setPriority()

void distortos::internal::ThreadControlBlock::setPriority ( uint8_t  priority,
bool  alwaysBehind = {} 
)

Changes priority of thread.

If the priority really changes, the position in the thread list is adjusted and context switch may be requested.

Parameters
[in]priorityis the new priority of thread
[in]alwaysBehindselects the method of ordering when lowering the priority
  • false - the thread is moved to the head of the group of threads with the new priority (default),
  • true - the thread is moved to the tail of the group of threads with the new priority.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setPriorityInheritanceMutexControlBlock()

void distortos::internal::ThreadControlBlock::setPriorityInheritanceMutexControlBlock ( const MutexControlBlock *const  priorityInheritanceMutexControlBlock)
inline
Parameters
[in]priorityInheritanceMutexControlBlockis a pointer to MutexControlBlock (with PriorityInheritance protocol) that blocks this thread
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setSchedulingPolicy()

void distortos::internal::ThreadControlBlock::setSchedulingPolicy ( SchedulingPolicy  schedulingPolicy)

param [in] schedulingPolicy is the new scheduling policy of the thread

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

◆ setState()

void distortos::internal::ThreadControlBlock::setState ( const ThreadState  state)
inline
Parameters
[in]stateis the new state of object
Here is the caller graph for this function:

◆ switchedToHook()

void distortos::internal::ThreadControlBlock::switchedToHook ( )
inline

Hook function called when context is switched to this thread.

Sets global _impure_ptr (from newlib) to thread's reent_ member variable.

Attention
This function should be called only by Scheduler::switchContext().
Here is the call graph for this function:

◆ unblockHook()

void distortos::internal::ThreadControlBlock::unblockHook ( UnblockReason  unblockReason)

Unblock hook function of thread.

Resets round-robin's quantum and executes unblock functor saved in blockHook().

Attention
This function should be called only by Scheduler::unblockInternal().
Parameters
[in]unblockReasonis the new reason of unblocking of the thread
Here is the call graph for this function:
Here is the caller graph for this function:

◆ updateBoostedPriority()

void distortos::internal::ThreadControlBlock::updateBoostedPriority ( uint8_t  boostedPriority = {})

Updates boosted priority of the thread.

This function should be called after all operations involving this thread and a mutex with enabled priority protocol.

Parameters
[in]boostedPriorityis the initial boosted priority, this should be effective priority of the thread that is about to be blocked on a mutex owned by this thread, default - 0
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ list_

ThreadList* distortos::internal::ThreadControlBlock::list_
private

pointer to list that has this object

◆ ownedProtocolMutexList_

MutexList distortos::internal::ThreadControlBlock::ownedProtocolMutexList_
private

list of mutexes (mutex control blocks) with enabled priority protocol owned by this thread

◆ owner_

Thread& distortos::internal::ThreadControlBlock::owner_
private

reference to Thread object that owns this ThreadControlBlock

◆ priorityInheritanceMutexControlBlock_

const MutexControlBlock* distortos::internal::ThreadControlBlock::priorityInheritanceMutexControlBlock_
private

pointer to MutexControlBlock (with PriorityInheritance protocol) that blocks this thread

◆ reent_

_reent distortos::internal::ThreadControlBlock::reent_
private

newlib's _reent structure with thread-specific data

◆ roundRobinQuantum_

RoundRobinQuantum distortos::internal::ThreadControlBlock::roundRobinQuantum_
private

round-robin quantum

◆ schedulingPolicy_

SchedulingPolicy distortos::internal::ThreadControlBlock::schedulingPolicy_
private

scheduling policy of the thread

◆ signalsReceiverControlBlock_

SignalsReceiverControlBlock* distortos::internal::ThreadControlBlock::signalsReceiverControlBlock_
private

pointer to SignalsReceiverControlBlock object for this thread, nullptr if this thread cannot receive signals

◆ stack_

Stack distortos::internal::ThreadControlBlock::stack_
private

internal stack object

◆ state_

ThreadState distortos::internal::ThreadControlBlock::state_
private

current state of object

◆ threadGroupControlBlock_

ThreadGroupControlBlock* distortos::internal::ThreadControlBlock::threadGroupControlBlock_
private

pointer to ThreadGroupControlBlock with which this object is associated

◆ unblockFunctor_

const UnblockFunctor* distortos::internal::ThreadControlBlock::unblockFunctor_
private

functor executed in unblockHook()


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