|
distortos
v0.7.0
object-oriented C++ RTOS for microcontrollers
|
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"
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 DynamicThreadBase & | operator= (const DynamicThreadBase &)=delete |
| DynamicThreadBase & | operator= (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 ThreadCommon & | operator= (const ThreadCommon &)=delete |
| ThreadCommon & | operator= (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... | |
| ThreadControlBlock & | getThreadControlBlock () |
| const ThreadControlBlock & | getThreadControlBlock () 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... | |
| DynamicThread * | owner_ |
| 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... | |
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.
| 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.
| Function | is the function that will be executed in separate thread |
| Args | are the arguments for Function |
| [in] | stackSize | is the size of stack, bytes |
| [in] | canReceiveSignals | selects whether reception of signals is enabled (true) or disabled (false) for this thread |
| [in] | queuedSignals | is the max number of queued signals for this thread, relevant only if canReceiveSignals == true, 0 to disable queuing of signals for this thread |
| [in] | signalActions | is 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] | priority | is the thread's priority, 0 - lowest, UINT8_MAX - highest |
| [in] | schedulingPolicy | is the scheduling policy of the thread |
| [in] | owner | is a reference to owner DynamicThread object |
| [in] | function | is a function that will be executed in separate thread |
| [in] | args | are arguments for function |
|
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.
Implements distortos::Thread.
|
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.
|
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.
|
inlinestaticprivate |
Helper function to make stack with size adjusted to alignment requirements.
Size of "stack guard" is added to function argument.
| [in] | stackSize | is the size of stack, bytes |
|
overrideprotectedvirtual |
Thread's "run" function.
Executes bound function object.
Implements distortos::internal::RunnableThread.
|
inline |
Starts the thread.
This operation can be performed on threads in "created" state only.
|
private |
bound function object
|
private |
internal DynamicSignalsReceiver object
|
private |
pointer to owner DynamicThread object, nullptr if thread is detached