distortos  v0.6.0
object-oriented C++ RTOS for microcontrollers
distortos::internal::ThreadCommon Class Reference

ThreadCommon class implements common functionality of threads. More...

#include "ThreadCommon.hpp"

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

Public Types

using StackStorageUniquePointer = Stack::StorageUniquePointer
 unique_ptr (with deleter) to storage for stack More...
 

Public Member Functions

 ThreadCommon (Stack &&stack, uint8_t priority, SchedulingPolicy schedulingPolicy, ThreadGroupControlBlock *threadGroupControlBlock, SignalsReceiver *signalsReceiver)
 ThreadCommon's constructor. More...
 
 ~ThreadCommon () override
 ThreadCommon's destructor. More...
 
int generateSignal (uint8_t signalNumber) override
 Generates signal for thread. More...
 
uint8_t getEffectivePriority () const override
 
ThreadIdentifier getIdentifier () const override
 
SignalSet getPendingSignalSet () const override
 Gets set of currently pending signals. More...
 
uint8_t getPriority () const override
 
SchedulingPolicy getSchedulingPolicy () const override
 
size_t getStackHighWaterMark () const override
 
size_t getStackSize () const override
 
ThreadState getState () const override
 
int join () override
 Waits for thread termination. More...
 
int queueSignal (uint8_t signalNumber, sigval value) override
 Queues signal for thread. More...
 
void setPriority (uint8_t priority, bool alwaysBehind={}) override
 Changes priority of thread. More...
 
void setSchedulingPolicy (SchedulingPolicy schedulingPolicy) override
 
 ThreadCommon (const ThreadCommon &)=delete
 
 ThreadCommon (ThreadCommon &&)=default
 
const ThreadCommonoperator= (const ThreadCommon &)=delete
 
ThreadCommonoperator= (ThreadCommon &&)=delete
 
- Public Member Functions inherited from distortos::Thread
virtual ~Thread ()=0
 Thread's destructor. More...
 
virtual int detach ()=0
 Detaches the thread. More...
 

Protected Member Functions

void exit0Hook () override
 Thread's "exit 0" hook function. More...
 
void exit1Hook () override
 Thread's "exit 1" hook function. More...
 
ThreadControlBlockgetThreadControlBlock ()
 
const ThreadControlBlockgetThreadControlBlock () const
 
int startInternal ()
 Starts the thread. More...
 
- Protected Member Functions inherited from distortos::internal::RunnableThread
virtual void run ()=0
 Thread's "run" function. More...
 

Private Attributes

ThreadControlBlock threadControlBlock_
 internal ThreadControlBlock object More...
 
Semaphore joinSemaphore_
 semaphore used by join() More...
 

Detailed Description

ThreadCommon class implements common functionality of threads.

Member Typedef Documentation

◆ StackStorageUniquePointer

unique_ptr (with deleter) to storage for stack

Constructor & Destructor Documentation

◆ ThreadCommon()

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

ThreadCommon's 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

◆ ~ThreadCommon()

distortos::internal::ThreadCommon::~ThreadCommon ( )
override

ThreadCommon's destructor.

Member Function Documentation

◆ exit0Hook()

void distortos::internal::ThreadCommon::exit0Hook ( )
overrideprotectedvirtual

Thread's "exit 0" hook function.

This hook will be called early during thread's exit - while the thread is still runnable.

Empty default implementation.

Implements distortos::internal::RunnableThread.

Here is the caller graph for this function:

◆ exit1Hook()

void distortos::internal::ThreadCommon::exit1Hook ( )
overrideprotectedvirtual

Thread's "exit 1" hook function.

This hook will be called late during thread's exit - after the thread is removed from the scheduler.

Posts join() semaphore.

Implements distortos::internal::RunnableThread.

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

◆ getEffectivePriority()

uint8_t distortos::internal::ThreadCommon::getEffectivePriority ( ) const
overridevirtual
Returns
effective priority of thread

Implements distortos::Thread.

Here is the call graph for this function:

◆ getIdentifier()

ThreadIdentifier distortos::internal::ThreadCommon::getIdentifier ( ) const
overridevirtual
Returns
identifier of thread, default-constructed ThreadIdentifier if this object doesn't represent a valid thread of execution (e.g. after the thread is detached)

Implements distortos::Thread.

Here is the call graph for this function:

◆ getPriority()

uint8_t distortos::internal::ThreadCommon::getPriority ( ) const
overridevirtual
Returns
priority of thread

Implements distortos::Thread.

Here is the call graph for this function:

◆ getSchedulingPolicy()

SchedulingPolicy distortos::internal::ThreadCommon::getSchedulingPolicy ( ) const
overridevirtual
Returns
scheduling policy of the thread

Implements distortos::Thread.

Here is the call graph for this function:

◆ getStackHighWaterMark()

size_t distortos::internal::ThreadCommon::getStackHighWaterMark ( ) const
overridevirtual
Returns
"high water mark" (max usage) of thread's stack, bytes

Implements distortos::Thread.

Here is the call graph for this function:

◆ getStackSize()

size_t distortos::internal::ThreadCommon::getStackSize ( ) const
overridevirtual
Returns
size of thread's stack, bytes

Implements distortos::Thread.

Here is the call graph for this function:

◆ getState()

ThreadState distortos::internal::ThreadCommon::getState ( ) const
overridevirtual
Returns
current state of thread

Implements distortos::Thread.

Here is the call graph for this function:

◆ getThreadControlBlock() [1/2]

ThreadControlBlock& distortos::internal::ThreadCommon::getThreadControlBlock ( )
inlineprotected
Returns
reference to internal ThreadControlBlock object
Here is the caller graph for this function:

◆ getThreadControlBlock() [2/2]

const ThreadControlBlock& distortos::internal::ThreadCommon::getThreadControlBlock ( ) const
inlineprotected
Returns
const reference to internal ThreadControlBlock object

◆ setPriority()

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

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.

Implements distortos::Thread.

Here is the call graph for this function:

◆ setSchedulingPolicy()

void distortos::internal::ThreadCommon::setSchedulingPolicy ( SchedulingPolicy  schedulingPolicy)
overridevirtual

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

Implements distortos::Thread.

Here is the call graph for this function:

◆ startInternal()

int distortos::internal::ThreadCommon::startInternal ( )
protected

Starts the thread.

This operation can be performed on threads in "created" state only.

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

Member Data Documentation

◆ joinSemaphore_

Semaphore distortos::internal::ThreadCommon::joinSemaphore_
private

semaphore used by join()

◆ threadControlBlock_

ThreadControlBlock distortos::internal::ThreadCommon::threadControlBlock_
private

internal ThreadControlBlock object


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