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

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

#include "distortos/DynamicThread.hpp"

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

Public Member Functions

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

Private Attributes

std::unique_ptr< internal::DynamicThreadBasedetachableThread_
 internal thread object More...
 

Detailed Description

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

Constructor & Destructor Documentation

◆ DynamicThread() [1/2]

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

DynamicThread'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]functionis a function that will be executed in separate thread
[in]argsare arguments for function

◆ DynamicThread() [2/2]

template<typename Function , typename... Args>
distortos::DynamicThread::DynamicThread ( const DynamicThreadParameters  parameters,
Function &&  function,
Args &&...  args 
)
inline

DynamicThread's constructor.

Template Parameters
Functionis the function that will be executed in separate thread
Argsare the arguments for Function
Parameters
[in]parametersis a DynamicThreadParameters struct with thread parameters
[in]functionis a function that will be executed in separate thread
[in]argsare arguments for function

◆ ~DynamicThread()

distortos::DynamicThread::~DynamicThread ( )
override

DynamicThread's destructor.

Member Function Documentation

◆ detach()

int distortos::DynamicThread::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.

Warning
This function must not be called from interrupt context!
Returns
0 on success, error code otherwise:

Implements distortos::Thread.

Here is the caller graph for this function:

◆ getEffectivePriority()

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

Implements distortos::Thread.

◆ getIdentifier()

ThreadIdentifier distortos::DynamicThread::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.

◆ getPriority()

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

Implements distortos::Thread.

◆ getSchedulingPolicy()

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

Implements distortos::Thread.

◆ getStackHighWaterMark()

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

Implements distortos::Thread.

◆ getStackSize()

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

Implements distortos::Thread.

◆ getState()

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

Implements distortos::Thread.

◆ setPriority()

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

◆ setSchedulingPolicy()

void distortos::DynamicThread::setSchedulingPolicy ( SchedulingPolicy  schedulingPolicy)
overridevirtual

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

Implements distortos::Thread.

◆ start()

int distortos::DynamicThread::start ( )

Starts the thread.

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

Returns
0 on success, error code otherwise:

Member Data Documentation

◆ detachableThread_

std::unique_ptr<internal::DynamicThreadBase> distortos::DynamicThread::detachableThread_
private

internal thread object


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