distortos  v0.4.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 internal DynamicSignalsReceiver object. More...

#include <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::ThreadCommon
 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...
 

Static Protected Member Functions

static void preTerminationHook (Thread &thread)
 Pre-termination hook function of thread. More...
 
static void terminationHook (Thread &thread)
 Termination hook function of thread. More...
 
- Static Protected Member Functions inherited from distortos::ThreadCommon
static void terminationHook (Thread &thread)
 Termination hook function of thread. More...
 

Static Private Member Functions

static void run (Thread &thread)
 Thread's "run" function. 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...
 

Static Private Attributes

static constexpr size_t stackGuardSize_
 size of "stack guard", bytes More...
 

Additional Inherited Members

- Public Types inherited from distortos::ThreadCommon
using StackStorageUniquePointer = internal::Stack::StorageUniquePointer
 unique_ptr (with deleter) to storage for stack More...
 
- Protected Member Functions inherited from distortos::ThreadCommon
internal::ThreadControlBlockgetThreadControlBlock ()
 
const internal::ThreadControlBlockgetThreadControlBlock () const
 
int startInternal (void(&runFunction)(Thread &), void(*preTerminationHookFunction)(Thread &), void(&terminationHookFunction)(Thread &))
 Starts the thread. More...
 

Detailed Description

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

If thread detachment is enabled (CONFIG_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 (CONFIG_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 caller 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:

◆ preTerminationHook()

void distortos::internal::DynamicThreadBase::preTerminationHook ( Thread thread)
staticprotected

Pre-termination hook function of thread.

If thread is detached, locks object used for deferred deletion.

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

◆ run()

void distortos::internal::DynamicThreadBase::run ( Thread thread)
staticprivate

Thread's "run" function.

Executes bound function object.

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

◆ start()

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

Starts the thread.

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

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

◆ terminationHook()

void distortos::internal::DynamicThreadBase::terminationHook ( Thread thread)
staticprotected

Termination hook function of thread.

Calls ThreadCommon::terminationHook() and - if thread is detached - schedules itself for deferred deletion.

Parameters
[in]threadis a reference to Thread object, this must be DynamicThreadBase!
Todo:
error handling?
Here is the call graph for this function:
Here is the caller 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

◆ stackGuardSize_

constexpr size_t distortos::internal::DynamicThreadBase::stackGuardSize_
staticprivate
Initial value:
{(CONFIG_STACK_GUARD_SIZE + CONFIG_ARCHITECTURE_STACK_ALIGNMENT - 1) /
CONFIG_ARCHITECTURE_STACK_ALIGNMENT * CONFIG_ARCHITECTURE_STACK_ALIGNMENT}

size of "stack guard", bytes


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