The Thread class allow defining, creating, and controlling thread functions in the system. More...
#include <Thread.h>
Public Types |
Public Member Functions | |
Thread (osPriority priority=osPriorityNormal, uint32_t stack_size=OS_STACK_SIZE, unsigned char *stack_mem=nullptr, const char *name=nullptr) | |
Allocate a new thread without starting execution. More... | |
Thread (uint32_t tz_module, osPriority priority=osPriorityNormal, uint32_t stack_size=OS_STACK_SIZE, unsigned char *stack_mem=nullptr, const char *name=nullptr) | |
Allocate a new thread without starting execution. More... | |
Thread (mbed::Callback< void()> task, osPriority priority=osPriorityNormal, uint32_t stack_size=OS_STACK_SIZE, unsigned char *stack_mem=nullptr) | |
Create a new thread, and start it executing the specified function. More... | |
template<typename T > | |
Thread (T *argument, void(T::*task)(), osPriority priority=osPriorityNormal, uint32_t stack_size=OS_STACK_SIZE, unsigned char *stack_mem=nullptr) | |
Create a new thread, and start it executing the specified function. More... | |
template<typename T > | |
Thread (T *argument, void(*task)(T *), osPriority priority=osPriorityNormal, uint32_t stack_size=OS_STACK_SIZE, unsigned char *stack_mem=nullptr) | |
Create a new thread, and start it executing the specified function. More... | |
Thread (void(*task)(void const *argument), void *argument=nullptr, osPriority priority=osPriorityNormal, uint32_t stack_size=OS_STACK_SIZE, unsigned char *stack_mem=nullptr) | |
Create a new thread, and start it executing the specified function. More... | |
osStatus | start (mbed::Callback< void()> task) |
Starts a thread executing the specified function. More... | |
template<typename T , typename M > | |
osStatus | start (T *obj, M method) |
Starts a thread executing the specified function. More... | |
osStatus | join () |
Wait for thread to terminate. More... | |
osStatus | terminate () |
Terminate execution of a thread and remove it from Active Threads. More... | |
osStatus | set_priority (osPriority priority) |
Set priority of an active thread. More... | |
osPriority | get_priority () const |
Get priority of an active thread. More... | |
uint32_t | flags_set (uint32_t flags) |
Set the specified Thread Flags for the thread. More... | |
int32_t | signal_set (int32_t signals) |
Set the specified Thread Flags for the thread. More... | |
State | get_state () const |
State of this Thread. More... | |
uint32_t | stack_size () const |
Get the total stack memory size for this Thread. More... | |
uint32_t | free_stack () const |
Get the currently unused stack memory for this Thread. More... | |
uint32_t | used_stack () const |
Get the currently used stack memory for this Thread. More... | |
uint32_t | max_stack () const |
Get the maximum stack memory usage to date for this Thread. More... | |
const char * | get_name () const |
Get thread name. More... | |
osThreadId_t | get_id () const |
Get thread id. More... | |
virtual | ~Thread () |
Thread destructor. More... | |
Static Public Member Functions | |
static int32_t | signal_clr (int32_t signals) |
Clears the specified Thread Flags of the currently running thread. More... | |
static osEvent | signal_wait (int32_t signals, uint32_t millisec=osWaitForever) |
Wait for one or more Thread Flags to become signaled for the current RUNNING thread. More... | |
static osStatus | wait (uint32_t millisec) |
Wait for a specified time period in milliseconds Being tick-based, the delay will be up to the specified time - eg for a value of 1 the system waits until the next millisecond tick occurs, leading to a delay of 0-1 milliseconds. More... | |
static osStatus | wait_until (uint64_t millisec) |
Wait until a specified time in millisec The specified time is according to Kernel::get_ms_count(). More... | |
static osStatus | yield () |
Pass control to next thread that is in state READY. More... | |
static osThreadId | gettid () |
Get the thread id of the current running thread. More... | |
static void | attach_idle_hook (void(*fptr)(void)) |
Attach a function to be called by the RTOS idle task. More... | |
static void | attach_terminate_hook (void(*fptr)(osThreadId id)) |
Attach a function to be called when a task is killed. More... | |
The Thread class allow defining, creating, and controlling thread functions in the system.
Example:
tz_module
as argument during thread creation.MBED_TZ_DEFAULT_ACCESS is target specific define, should be set in targets.json file for Cortex-M23/M33 devices.
enum State |
State of the Thread.
Enumerator | |
---|---|
Inactive |
NOT USED. |
Ready |
Ready to run. |
Running |
Running. |
WaitingDelay |
Waiting for a delay to occur. |
WaitingJoin |
Waiting for thread to join. Only happens when using RTX directly. |
WaitingThreadFlag |
Waiting for a thread flag to be set. |
WaitingEventFlag |
Waiting for a event flag to be set. |
WaitingMutex |
Waiting for a mutex event to occur. |
WaitingSemaphore |
Waiting for a semaphore event to occur. |
WaitingMemoryPool |
Waiting for a memory pool. |
WaitingMessageGet |
Waiting for message to arrive. |
WaitingMessagePut |
Waiting for message to be send. |
WaitingInterval |
NOT USED. |
WaitingOr |
NOT USED. |
WaitingAnd |
NOT USED. |
WaitingMailbox |
NOT USED (Mail is implemented as MemoryPool and Queue) |
Deleted |
The task has been deleted or not started. |
Thread | ( | osPriority | priority = osPriorityNormal , |
uint32_t | stack_size = OS_STACK_SIZE , |
||
unsigned char * | stack_mem = nullptr , |
||
const char * | name = nullptr |
||
) |
Allocate a new thread without starting execution.
priority | initial priority of the thread function. (default: osPriorityNormal). |
stack_size | stack size (in bytes) requirements for the thread function. (default: OS_STACK_SIZE). |
stack_mem | pointer to the stack area to be used by this thread (default: nullptr). |
name | name to be used for this thread. It has to stay allocated for the lifetime of the thread (default: nullptr) |
Thread | ( | uint32_t | tz_module, |
osPriority | priority = osPriorityNormal , |
||
uint32_t | stack_size = OS_STACK_SIZE , |
||
unsigned char * | stack_mem = nullptr , |
||
const char * | name = nullptr |
||
) |
Allocate a new thread without starting execution.
tz_module | trustzone thread identifier (osThreadAttr_t::tz_module) Context of RTOS threads in non-secure state must be saved when calling secure functions. tz_module ID is used to allocate context memory for threads, and it can be safely set to zero for threads not using secure calls at all. See "TrustZone RTOS Context Management" for more details. |
priority | initial priority of the thread function. (default: osPriorityNormal). |
stack_size | stack size (in bytes) requirements for the thread function. (default: OS_STACK_SIZE). |
stack_mem | pointer to the stack area to be used by this thread (default: nullptr). |
name | name to be used for this thread. It has to stay allocated for the lifetime of the thread (default: nullptr) |
Thread | ( | mbed::Callback< void()> | task, |
osPriority | priority = osPriorityNormal , |
||
uint32_t | stack_size = OS_STACK_SIZE , |
||
unsigned char * | stack_mem = nullptr |
||
) |
Create a new thread, and start it executing the specified function.
task | function to be executed by this thread. |
priority | initial priority of the thread function. (default: osPriorityNormal). |
stack_size | stack size (in bytes) requirements for the thread function. (default: OS_STACK_SIZE). |
stack_mem | pointer to the stack area to be used by this thread (default: nullptr). |
Thread | ( | T * | argument, |
void(T::*)() | task, | ||
osPriority | priority = osPriorityNormal , |
||
uint32_t | stack_size = OS_STACK_SIZE , |
||
unsigned char * | stack_mem = nullptr |
||
) |
Create a new thread, and start it executing the specified function.
argument | pointer that is passed to the thread function as start argument. (default: nullptr). |
task | argument to task. |
priority | initial priority of the thread function. (default: osPriorityNormal). |
stack_size | stack size (in bytes) requirements for the thread function. (default: OS_STACK_SIZE). |
stack_mem | pointer to the stack area to be used by this thread (default: nullptr). |
Thread | ( | T * | argument, |
void(*)(T *) | task, | ||
osPriority | priority = osPriorityNormal , |
||
uint32_t | stack_size = OS_STACK_SIZE , |
||
unsigned char * | stack_mem = nullptr |
||
) |
Create a new thread, and start it executing the specified function.
argument | pointer that is passed to the thread function as start argument. (default: nullptr). |
task | argument to task. |
priority | initial priority of the thread function. (default: osPriorityNormal). |
stack_size | stack size (in bytes) requirements for the thread function. (default: OS_STACK_SIZE). |
stack_mem | pointer to the stack area to be used by this thread (default: nullptr). |
Thread | ( | void(*)(void const *argument) | task, |
void * | argument = nullptr , |
||
osPriority | priority = osPriorityNormal , |
||
uint32_t | stack_size = OS_STACK_SIZE , |
||
unsigned char * | stack_mem = nullptr |
||
) |
Create a new thread, and start it executing the specified function.
Provided for backwards compatibility
task | function to be executed by this thread. |
argument | pointer that is passed to the thread function as start argument. (default: nullptr). |
priority | initial priority of the thread function. (default: osPriorityNormal). |
stack_size | stack size (in bytes) requirements for the thread function. (default: OS_STACK_SIZE). |
stack_mem | pointer to the stack area to be used by this thread (default: nullptr). |
|
static |
Attach a function to be called by the RTOS idle task.
fptr | pointer to the function to be called |
|
static |
Attach a function to be called when a task is killed.
fptr | pointer to the function to be called |
uint32_t flags_set | ( | uint32_t | flags | ) |
Set the specified Thread Flags for the thread.
flags | specifies the flags of the thread that should be set. |
uint32_t free_stack | ( | ) | const |
Get the currently unused stack memory for this Thread.
osThreadId_t get_id | ( | ) | const |
Get thread id.
const char* get_name | ( | ) | const |
Get thread name.
osPriority get_priority | ( | ) | const |
Get priority of an active thread.
State get_state | ( | ) | const |
|
static |
Get the thread id of the current running thread.
osStatus join | ( | ) |
Wait for thread to terminate.
uint32_t max_stack | ( | ) | const |
Get the maximum stack memory usage to date for this Thread.
osStatus set_priority | ( | osPriority | priority | ) |
Set priority of an active thread.
priority | new priority value for the thread function. |
|
static |
Clears the specified Thread Flags of the currently running thread.
signals | specifies the signal flags of the thread that should be cleared. |
int32_t signal_set | ( | int32_t | signals | ) |
Set the specified Thread Flags for the thread.
signals | specifies the signal flags of the thread that should be set. |
|
static |
Wait for one or more Thread Flags to become signaled for the current RUNNING thread.
signals | wait until all specified signal flags are set or 0 for any single signal flag. |
millisec | timeout value. (default: osWaitForever). |
uint32_t stack_size | ( | ) | const |
Get the total stack memory size for this Thread.
osStatus start | ( | mbed::Callback< void()> | task | ) |
Starts a thread executing the specified function.
task | function to be executed by this thread. |
osStatus start | ( | T * | obj, |
M | method | ||
) |
Starts a thread executing the specified function.
obj | argument to task |
method | function to be executed by this thread. |
osStatus terminate | ( | ) |
Terminate execution of a thread and remove it from Active Threads.
uint32_t used_stack | ( | ) | const |
Get the currently used stack memory for this Thread.
|
static |
Wait for a specified time period in milliseconds Being tick-based, the delay will be up to the specified time - eg for a value of 1 the system waits until the next millisecond tick occurs, leading to a delay of 0-1 milliseconds.
millisec | time delay value |
|
static |
Wait until a specified time in millisec The specified time is according to Kernel::get_ms_count().
millisec | absolute time in millisec |
|
static |
Pass control to next thread that is in state READY.