Furi: Furi Thread API. More...
#include "base.h"
#include "common_defines.h"
#include <stdint.h>
#include <stddef.h>
Go to the source code of this file.
Typedefs | |
typedef struct FuriThread | FuriThread |
FuriThread opaque type. | |
typedef struct FuriThreadList | FuriThreadList |
FuriThreadList type. | |
typedef void * | FuriThreadId |
Unique thread identifier type (used by the OS kernel). | |
typedef int32_t(* | FuriThreadCallback) (void *context) |
Thread callback function pointer type. | |
typedef void(* | FuriThreadStdoutWriteCallback) (const char *data, size_t size) |
Standard output callback function pointer type. | |
typedef void(* | FuriThreadStateCallback) (FuriThread *thread, FuriThreadState state, void *context) |
State change callback function pointer type. | |
typedef bool(* | FuriThreadSignalCallback) (uint32_t signal, void *arg, void *context) |
Signal handler callback function pointer type. | |
Enumerations | |
enum | FuriThreadState { FuriThreadStateStopped , FuriThreadStateStopping , FuriThreadStateStarting , FuriThreadStateRunning } |
Enumeration of possible FuriThread states. More... | |
enum | FuriThreadPriority { FuriThreadPriorityIdle = 0 , FuriThreadPriorityInit = 4 , FuriThreadPriorityLowest = 14 , FuriThreadPriorityLow = 15 , FuriThreadPriorityNormal = 16 , FuriThreadPriorityHigh = 17 , FuriThreadPriorityHighest = 18 , FuriThreadPriorityIsr } |
Enumeration of possible FuriThread priorities. More... | |
Functions | |
FuriThread * | furi_thread_alloc (void) |
Create a FuriThread instance. | |
FuriThread * | furi_thread_alloc_service (const char *name, uint32_t stack_size, FuriThreadCallback callback, void *context) |
Create a FuriThread instance (service mode). | |
FuriThread * | furi_thread_alloc_ex (const char *name, uint32_t stack_size, FuriThreadCallback callback, void *context) |
Create a FuriThread instance w/ extra parameters. | |
void | furi_thread_free (FuriThread *thread) |
Delete a FuriThread instance. | |
void | furi_thread_set_name (FuriThread *thread, const char *name) |
Set the name of a FuriThread instance. | |
void | furi_thread_set_appid (FuriThread *thread, const char *appid) |
Set the application ID of a FuriThread instance. | |
void | furi_thread_set_stack_size (FuriThread *thread, size_t stack_size) |
Set the stack size of a FuriThread instance. | |
void | furi_thread_set_callback (FuriThread *thread, FuriThreadCallback callback) |
Set the user callback function to be executed in a FuriThread. | |
void | furi_thread_set_context (FuriThread *thread, void *context) |
Set the callback function context. | |
void | furi_thread_set_priority (FuriThread *thread, FuriThreadPriority priority) |
Set the priority of a FuriThread. | |
FuriThreadPriority | furi_thread_get_priority (FuriThread *thread) |
Get the priority of a FuriThread. | |
void | furi_thread_set_current_priority (FuriThreadPriority priority) |
Set the priority of the current FuriThread. | |
FuriThreadPriority | furi_thread_get_current_priority (void) |
Get the priority of the current FuriThread. | |
void | furi_thread_set_state_callback (FuriThread *thread, FuriThreadStateCallback callback) |
Set the callback function to be executed upon a state thransition of a FuriThread. | |
void | furi_thread_set_state_context (FuriThread *thread, void *context) |
Set the state change callback context. | |
FuriThreadState | furi_thread_get_state (FuriThread *thread) |
Get the state of a FuriThread isntance. | |
void | furi_thread_set_signal_callback (FuriThread *thread, FuriThreadSignalCallback callback, void *context) |
Set a signal handler callback for a FuriThread instance. | |
FuriThreadSignalCallback | furi_thread_get_signal_callback (const FuriThread *thread) |
Get a signal callback for a FuriThread instance. | |
bool | furi_thread_signal (const FuriThread *thread, uint32_t signal, void *arg) |
Send a signal to a FuriThread instance. | |
void | furi_thread_start (FuriThread *thread) |
Start a FuriThread instance. | |
bool | furi_thread_join (FuriThread *thread) |
Wait for a FuriThread to exit. | |
FuriThreadId | furi_thread_get_id (FuriThread *thread) |
Get the unique identifier of a FuriThread instance. | |
void | furi_thread_enable_heap_trace (FuriThread *thread) |
Enable heap usage tracing for a FuriThread. | |
void | furi_thread_disable_heap_trace (FuriThread *thread) |
Disable heap usage tracing for a FuriThread. | |
size_t | furi_thread_get_heap_size (FuriThread *thread) |
Get heap usage by a FuriThread instance. | |
int32_t | furi_thread_get_return_code (FuriThread *thread) |
Get the return code of a FuriThread instance. | |
FuriThreadId | furi_thread_get_current_id (void) |
Get the unique identifier of the current FuriThread. | |
FuriThread * | furi_thread_get_current (void) |
Get the FuriThread instance associated with the current thread. | |
void | furi_thread_yield (void) |
Return control to the scheduler. | |
uint32_t | furi_thread_flags_set (FuriThreadId thread_id, uint32_t flags) |
Set the thread flags of a FuriThread. | |
uint32_t | furi_thread_flags_clear (uint32_t flags) |
Clear the thread flags of the current FuriThread. | |
uint32_t | furi_thread_flags_get (void) |
Get the thread flags of the current FuriThread. | |
uint32_t | furi_thread_flags_wait (uint32_t flags, uint32_t options, uint32_t timeout) |
Wait for some thread flags to be set. | |
bool | furi_thread_enumerate (FuriThreadList *thread_list) |
Enumerate all threads. | |
const char * | furi_thread_get_name (FuriThreadId thread_id) |
Get the name of a thread based on its unique identifier. | |
const char * | furi_thread_get_appid (FuriThreadId thread_id) |
Get the application id of a thread based on its unique identifier. | |
uint32_t | furi_thread_get_stack_space (FuriThreadId thread_id) |
Get thread stack watermark. | |
FuriThreadStdoutWriteCallback | furi_thread_get_stdout_callback (void) |
Get the standard output callback for the current thead. | |
void | furi_thread_set_stdout_callback (FuriThreadStdoutWriteCallback callback) |
Set standard output callback for the current thread. | |
size_t | furi_thread_stdout_write (const char *data, size_t size) |
Write data to buffered standard output. | |
int32_t | furi_thread_stdout_flush (void) |
Flush buffered data to standard output. | |
void | furi_thread_suspend (FuriThreadId thread_id) |
Suspend a thread. | |
void | furi_thread_resume (FuriThreadId thread_id) |
Resume a thread. | |
bool | furi_thread_is_suspended (FuriThreadId thread_id) |
Test if a thread is suspended. | |
Furi: Furi Thread API.
typedef int32_t(* FuriThreadCallback) (void *context) |
Thread callback function pointer type.
The function to be used as a thread callback MUST follow this signature.
[in,out] | context | pointer to a user-specified object |
typedef struct FuriThreadList FuriThreadList |
FuriThreadList type.
Anonymous FuriThreadList type.
typedef bool(* FuriThreadSignalCallback) (uint32_t signal, void *arg, void *context) |
Signal handler callback function pointer type.
The function to be used as a signal handler callback MUS follow this signature.
[in] | signal | value of the signal to be handled by the recipient |
[in,out] | arg | optional argument (can be of any value, including NULL) |
[in,out] | context | pointer to a user-specified object |
typedef void(* FuriThreadStateCallback) (FuriThread *thread, FuriThreadState state, void *context) |
State change callback function pointer type.
The function to be used as a state callback MUST follow this signature.
[in] | thread | to the FuriThread instance that changed the state |
[in] | state | identifier of the state the thread has transitioned to |
[in,out] | context | pointer to a user-specified object |
typedef void(* FuriThreadStdoutWriteCallback) (const char *data, size_t size) |
Standard output callback function pointer type.
The function to be used as a standard output callback MUST follow this signature.
[in] | data | pointer to the data to be written to the standard out |
[in] | size | size of the data in bytes |
enum FuriThreadPriority |
Enumeration of possible FuriThread priorities.
enum FuriThreadState |
Enumeration of possible FuriThread states.
Many of the FuriThread functions MUST ONLY be called when the thread is STOPPED.
FuriThread * furi_thread_alloc | ( | void | ) |
Create a FuriThread instance.
FuriThread * furi_thread_alloc_ex | ( | const char * | name, |
uint32_t | stack_size, | ||
FuriThreadCallback | callback, | ||
void * | context ) |
Create a FuriThread instance w/ extra parameters.
[in] | name | human-readable thread name (can be NULL) |
[in] | stack_size | stack size in bytes (can be changed later) |
[in] | callback | pointer to a function to be executed in this thread |
[in] | context | pointer to a user-specified object (will be passed to the callback) |
FuriThread * furi_thread_alloc_service | ( | const char * | name, |
uint32_t | stack_size, | ||
FuriThreadCallback | callback, | ||
void * | context ) |
Create a FuriThread instance (service mode).
Service threads are more memory efficient, but have the following limitations:
[in] | name | human-readable thread name (can be NULL) |
[in] | stack_size | stack size in bytes (cannot be changed later) |
[in] | callback | pointer to a function to be executed in this thread |
[in] | context | pointer to a user-specified object (will be passed to the callback) |
void furi_thread_disable_heap_trace | ( | FuriThread * | thread | ) |
Disable heap usage tracing for a FuriThread.
The thread MUST be stopped when calling this function.
[in,out] | thread | pointer to the FuriThread instance to be modified |
void furi_thread_enable_heap_trace | ( | FuriThread * | thread | ) |
Enable heap usage tracing for a FuriThread.
The thread MUST be stopped when calling this function.
[in,out] | thread | pointer to the FuriThread instance to be modified |
bool furi_thread_enumerate | ( | FuriThreadList * | thread_list | ) |
Enumerate all threads.
[out] | thread_list | pointer to the FuriThreadList container |
uint32_t furi_thread_flags_clear | ( | uint32_t | flags | ) |
Clear the thread flags of the current FuriThread.
[in] | flags | bitmask of thread flags to clear |
uint32_t furi_thread_flags_get | ( | void | ) |
Get the thread flags of the current FuriThread.
uint32_t furi_thread_flags_set | ( | FuriThreadId | thread_id, |
uint32_t | flags ) |
Set the thread flags of a FuriThread.
Can be used as a simple inter-thread communication mechanism.
[in] | thread_id | unique identifier of the thread to be notified |
[in] | flags | bitmask of thread flags to set |
uint32_t furi_thread_flags_wait | ( | uint32_t | flags, |
uint32_t | options, | ||
uint32_t | timeout ) |
Wait for some thread flags to be set.
[in] | flags | bitmask of thread flags to wait for |
[in] | options | combination of option flags determining the behavior of the function |
[in] | timeout | maximum time to wait in milliseconds (use FuriWaitForever to wait forever) |
void furi_thread_free | ( | FuriThread * | thread | ) |
Delete a FuriThread instance.
The thread MUST be stopped when calling this function.
[in,out] | thread | pointer to the FuriThread instance to be deleted |
const char * furi_thread_get_appid | ( | FuriThreadId | thread_id | ) |
Get the application id of a thread based on its unique identifier.
[in] | thread_id | unique identifier of the thread to be queried |
FuriThread * furi_thread_get_current | ( | void | ) |
Get the FuriThread instance associated with the current thread.
FuriThreadId furi_thread_get_current_id | ( | void | ) |
Get the unique identifier of the current FuriThread.
FuriThreadPriority furi_thread_get_current_priority | ( | void | ) |
Get the priority of the current FuriThread.
size_t furi_thread_get_heap_size | ( | FuriThread * | thread | ) |
Get heap usage by a FuriThread instance.
The heap trace MUST be enabled before callgin this function.
[in] | thread | pointer to the FuriThread instance to be queried |
FuriThreadId furi_thread_get_id | ( | FuriThread * | thread | ) |
Get the unique identifier of a FuriThread instance.
[in] | thread | pointer to the FuriThread instance to be queried |
const char * furi_thread_get_name | ( | FuriThreadId | thread_id | ) |
Get the name of a thread based on its unique identifier.
[in] | thread_id | unique identifier of the thread to be queried |
FuriThreadPriority furi_thread_get_priority | ( | FuriThread * | thread | ) |
Get the priority of a FuriThread.
[in] | thread | pointer to the FuriThread instance to be queried |
int32_t furi_thread_get_return_code | ( | FuriThread * | thread | ) |
Get the return code of a FuriThread instance.
This value is equal to the return value of the thread callback function.
The thread MUST be stopped when calling this function.
[in] | thread | pointer to the FuriThread instance to be queried |
FuriThreadSignalCallback furi_thread_get_signal_callback | ( | const FuriThread * | thread | ) |
Get a signal callback for a FuriThread instance.
[in] | thread | pointer to the FuriThread instance to be queried |
uint32_t furi_thread_get_stack_space | ( | FuriThreadId | thread_id | ) |
Get thread stack watermark.
[in] | thread_id | unique identifier of the thread to be queried |
FuriThreadState furi_thread_get_state | ( | FuriThread * | thread | ) |
Get the state of a FuriThread isntance.
[in] | thread | pointer to the FuriThread instance to be queried |
FuriThreadStdoutWriteCallback furi_thread_get_stdout_callback | ( | void | ) |
Get the standard output callback for the current thead.
bool furi_thread_is_suspended | ( | FuriThreadId | thread_id | ) |
Test if a thread is suspended.
[in] | thread_id | unique identifier of the thread to be queried |
bool furi_thread_join | ( | FuriThread * | thread | ) |
Wait for a FuriThread to exit.
The thread callback function must return in order for the FuriThread instance to become joinable.
[in] | thread | pointer to the FuriThread instance to be joined |
void furi_thread_resume | ( | FuriThreadId | thread_id | ) |
Resume a thread.
[in] | thread_id | unique identifier of the thread to be resumed |
void furi_thread_set_appid | ( | FuriThread * | thread, |
const char * | appid ) |
Set the application ID of a FuriThread instance.
The thread MUST be stopped when calling this function.
Technically, it is like a "process id", but it is not a system-wide unique identifier. All threads spawned by the same app will have the same appid.
[in,out] | thread | pointer to the FuriThread instance to be modified |
[in] | appid | thread application ID (can be NULL) |
void furi_thread_set_callback | ( | FuriThread * | thread, |
FuriThreadCallback | callback ) |
Set the user callback function to be executed in a FuriThread.
The thread MUST be stopped when calling this function.
[in,out] | thread | pointer to the FuriThread instance to be modified |
[in] | callback | pointer to a user-specified function to be executed in this thread |
void furi_thread_set_context | ( | FuriThread * | thread, |
void * | context ) |
Set the callback function context.
The thread MUST be stopped when calling this function.
[in,out] | thread | pointer to the FuriThread instance to be modified |
[in] | context | pointer to a user-specified object (will be passed to the callback, can be NULL) |
void furi_thread_set_current_priority | ( | FuriThreadPriority | priority | ) |
Set the priority of the current FuriThread.
priority | priority level value |
void furi_thread_set_name | ( | FuriThread * | thread, |
const char * | name ) |
Set the name of a FuriThread instance.
The thread MUST be stopped when calling this function.
[in,out] | thread | pointer to the FuriThread instance to be modified |
[in] | name | human-readable thread name (can be NULL) |
void furi_thread_set_priority | ( | FuriThread * | thread, |
FuriThreadPriority | priority ) |
Set the priority of a FuriThread.
The thread MUST be stopped when calling this function.
[in,out] | thread | pointer to the FuriThread instance to be modified |
[in] | priority | priority level value |
void furi_thread_set_signal_callback | ( | FuriThread * | thread, |
FuriThreadSignalCallback | callback, | ||
void * | context ) |
Set a signal handler callback for a FuriThread instance.
The thread MUST be stopped when calling this function if calling it from another thread.
[in,out] | thread | pointer to the FuriThread instance to be modified |
[in] | callback | pointer to a user-specified callback function |
[in] | context | pointer to a user-specified object (will be passed to the callback, can be NULL) |
void furi_thread_set_stack_size | ( | FuriThread * | thread, |
size_t | stack_size ) |
Set the stack size of a FuriThread instance.
The thread MUST be stopped when calling this function. Additionally, it is NOT possible to change the stack size of a service thread under any circumstances.
[in,out] | thread | pointer to the FuriThread instance to be modified |
[in] | stack_size | stack size in bytes |
void furi_thread_set_state_callback | ( | FuriThread * | thread, |
FuriThreadStateCallback | callback ) |
Set the callback function to be executed upon a state thransition of a FuriThread.
The thread MUST be stopped when calling this function.
[in,out] | thread | pointer to the FuriThread instance to be modified |
[in] | callback | pointer to a user-specified callback function |
void furi_thread_set_state_context | ( | FuriThread * | thread, |
void * | context ) |
Set the state change callback context.
The thread MUST be stopped when calling this function.
[in,out] | thread | pointer to the FuriThread instance to be modified |
[in] | context | pointer to a user-specified object (will be passed to the callback, can be NULL) |
void furi_thread_set_stdout_callback | ( | FuriThreadStdoutWriteCallback | callback | ) |
Set standard output callback for the current thread.
[in] | callback | pointer to the callback function or NULL to clear |
bool furi_thread_signal | ( | const FuriThread * | thread, |
uint32_t | signal, | ||
void * | arg ) |
Send a signal to a FuriThread instance.
[in] | thread | pointer to the FuriThread instance to be signaled |
[in] | signal | signal value to be sent |
[in,out] | arg | optional argument (can be of any value, including NULL) |
void furi_thread_start | ( | FuriThread * | thread | ) |
Start a FuriThread instance.
The thread MUST be stopped when calling this function.
[in,out] | thread | pointer to the FuriThread instance to be started |
int32_t furi_thread_stdout_flush | ( | void | ) |
Flush buffered data to standard output.
size_t furi_thread_stdout_write | ( | const char * | data, |
size_t | size ) |
Write data to buffered standard output.
[in] | data | pointer to the data to be written |
[in] | size | data size in bytes |
void furi_thread_suspend | ( | FuriThreadId | thread_id | ) |
Suspend a thread.
Suspended threads are no more receiving any of the processor time.
[in] | thread_id | unique identifier of the thread to be suspended |