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

DynamicThreadBase class is a type-erased interface for thread that has dynamic storage for bound function, stack and - if signals are enabled - internal DynamicSignalsReceiver object. More...

#include "distortos/internal/scheduler/DynamicThreadBase.hpp"

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

Public Member Functions

template<typename Function , typename... Args>
 DynamicThreadBase (size_t stackSize, bool canReceiveSignals, size_t queuedSignals, size_t signalActions, uint8_t priority, SchedulingPolicy schedulingPolicy, DynamicThread &owner, Function &&function, Args &&... args)
 DynamicThreadBase's constructor. More...
 
int detach () override
 Detaches the thread. More...
 
int start ()
 Starts the thread. More...
 
 DynamicThreadBase (const DynamicThreadBase &)=delete
 
 DynamicThreadBase (DynamicThreadBase &&)=default
 
const DynamicThreadBaseoperator= (const DynamicThreadBase &)=delete
 
DynamicThreadBaseoperator= (DynamicThreadBase &&)=delete
 
- Public Member Functions inherited from distortos::internal::ThreadCommon
 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 ()=default
 Thread's destructor. More...
 

Protected Member Functions

void exit0Hook () override
 Thread's "exit 0" hook function. More...
 
void exit1Hook () override
 Thread's "exit 1" hook function. More...
 
void run () override
 Thread's "run" function. More...
 
- Protected Member Functions inherited from distortos::internal::ThreadCommon
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...
 

Static Private Member Functions

static Stack makeStack (const size_t stackSize)
 Helper function to make stack with size adjusted to alignment requirements. More...
 

Private Attributes

DynamicSignalsReceiver dynamicSignalsReceiver_
 internal DynamicSignalsReceiver object More...
 
std::function< void()> boundFunction_
 bound function object More...
 
DynamicThreadowner_
 pointer to owner DynamicThread object, nullptr if thread is detached More...
 

Additional Inherited Members

- Public Types inherited from distortos::internal::ThreadCommon
using StackStorageUniquePointer = Stack::StorageUniquePointer
 unique_ptr (with deleter) to storage for stack More...
 

Detailed Description

DynamicThreadBase class is a type-erased interface for thread that has dynamic storage for bound function, stack and - if signals are enabled - internal DynamicSignalsReceiver object.

If thread detachment is enabled (DISTORTOS_THREAD_DETACH_ENABLE is defined) then this class is dynamically allocated by DynamicThread - which allows it to be "detached". Otherwise - if thread detachment is disabled (DISTORTOS_THREAD_DETACH_ENABLE is not defined) - DynamicThread just inherits from this class.

Constructor & Destructor Documentation

◆ DynamicThreadBase()

template<typename Function , typename... Args>
distortos::internal::DynamicThreadBase::DynamicThreadBase ( size_t  stackSize,
bool  canReceiveSignals,
size_t  queuedSignals,
size_t  signalActions,
uint8_t  priority,
SchedulingPolicy  schedulingPolicy,
DynamicThread owner,
Function &&  function,
Args &&...  args 
)

DynamicThreadBase's constructor.

Template Parameters
Functionis the function that will be executed in separate thread
Argsare the arguments for Function
Parameters
[in]stackSizeis the size of stack, bytes
[in]canReceiveSignalsselects whether reception of signals is enabled (true) or disabled (false) for this thread
[in]queuedSignalsis the max number of queued signals for this thread, relevant only if canReceiveSignals == true, 0 to disable queuing of signals for this thread
[in]signalActionsis the max number of different SignalAction objects for this thread, relevant only if canReceiveSignals == true, 0 to disable catching of signals for this thread
[in]priorityis the thread's priority, 0 - lowest, UINT8_MAX - highest
[in]schedulingPolicyis the scheduling policy of the thread
[in]owneris a reference to owner DynamicThread object
[in]functionis a function that will be executed in separate thread
[in]argsare arguments for function
Here is the call graph for this function:

Member Function Documentation

◆ detach()

int distortos::internal::DynamicThreadBase::detach ( )
overridevirtual

Detaches the thread.

Similar to std::thread::detach() - http://en.cppreference.com/w/cpp/thread/thread/detach Similar to POSIX pthread_detach() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_detach.html

Detaches the executing thread from the Thread object, allowing execution to continue independently. All resources allocated for the thread will be deallocated when the thread terminates.

Returns
0 on success, error code otherwise:
  • EINVAL - this thread is already detached;

Implements distortos::Thread.

Here is the call graph for this function:

◆ exit0Hook()

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

Thread's "exit 0" hook function.

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

Calls "exit 0" hook of base class and - if thread is detached - locks object used for deferred deletion.

Implements distortos::internal::RunnableThread.

Here is the call graph for this function:

◆ exit1Hook()

void distortos::internal::DynamicThreadBase::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.

Calls "exit 1" hook of base class and - if thread is detached - schedules itself for deferred deletion.

Implements distortos::internal::RunnableThread.

Here is the call graph for this function:

◆ makeStack()

static Stack distortos::internal::DynamicThreadBase::makeStack ( const size_t  stackSize)
inlinestaticprivate

Helper function to make stack with size adjusted to alignment requirements.

Size of "stack guard" is added to function argument.

Parameters
[in]stackSizeis the size of stack, bytes
Returns
Stack object with size adjusted to alignment requirements
Here is the caller graph for this function:

◆ run()

void distortos::internal::DynamicThreadBase::run ( )
overrideprotectedvirtual

Thread's "run" function.

Executes bound function object.

Implements distortos::internal::RunnableThread.

◆ start()

int distortos::internal::DynamicThreadBase::start ( )
inline

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:

Member Data Documentation

◆ boundFunction_

std::function<void()> distortos::internal::DynamicThreadBase::boundFunction_
private

bound function object

◆ dynamicSignalsReceiver_

DynamicSignalsReceiver distortos::internal::DynamicThreadBase::dynamicSignalsReceiver_
private

internal DynamicSignalsReceiver object

◆ owner_

DynamicThread* distortos::internal::DynamicThreadBase::owner_
private

pointer to owner DynamicThread object, nullptr if thread is detached


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