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

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

#include <ThreadCommon.hpp>

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

Public Types

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

Public Member Functions

 ThreadCommon (internal::Stack &&stack, uint8_t priority, SchedulingPolicy schedulingPolicy, internal::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
 
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

internal::ThreadControlBlockgetThreadControlBlock ()
 
const internal::ThreadControlBlockgetThreadControlBlock () const
 
int startInternal (void(&runFunction)(Thread &), void(*preTerminationHookFunction)(Thread &), void(&terminationHookFunction)(Thread &))
 Starts the thread. More...
 

Static Protected Member Functions

static void terminationHook (Thread &thread)
 Termination hook function of thread. More...
 

Private Attributes

internal::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::ThreadCommon::ThreadCommon ( internal::Stack &&  stack,
uint8_t  priority,
SchedulingPolicy  schedulingPolicy,
internal::ThreadGroupControlBlock threadGroupControlBlock,
SignalsReceiver signalsReceiver 
)

ThreadCommon's constructor.

Parameters
[in]stackis an rvalue reference to internal::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 internal::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::ThreadCommon::~ThreadCommon ( )
override

ThreadCommon's destructor.

Member Function Documentation

◆ getEffectivePriority()

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

Implements distortos::Thread.

Here is the call graph for this function:

◆ getPriority()

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

Implements distortos::Thread.

Here is the call graph for this function:

◆ getSchedulingPolicy()

SchedulingPolicy distortos::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::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::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::ThreadCommon::getState ( ) const
overridevirtual
Returns
current state of thread

Implements distortos::Thread.

Here is the call graph for this function:

◆ getThreadControlBlock() [1/2]

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

◆ getThreadControlBlock() [2/2]

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

◆ setPriority()

void distortos::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::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::ThreadCommon::startInternal ( void(&)(Thread &)  runFunction,
void(*)(Thread &)  preTerminationHookFunction,
void(&)(Thread &)  terminationHookFunction 
)
protected

Starts the thread.

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

Parameters
[in]runFunctionis a reference to Thread's "run" function
[in]preTerminationHookFunctionis a pointer to Thread's pre-termination hook, nullptr to skip
[in]terminationHookFunctionis a reference to Thread's termination hook
Returns
0 on success, error code otherwise:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ terminationHook()

void distortos::ThreadCommon::terminationHook ( Thread thread)
staticprotected

Termination hook function of thread.

Parameters
[in]threadis a reference to Thread object, this must be ThreadCommon!
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ joinSemaphore_

Semaphore distortos::ThreadCommon::joinSemaphore_
private

semaphore used by join()

◆ threadControlBlock_

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

internal ThreadControlBlock object


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