Loading...
Searching...
No Matches
thread.h
Go to the documentation of this file.
1
6#pragma once
7
8#include "base.h"
9#include "common_defines.h"
10
11#include <stdint.h>
12#include <stddef.h>
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
29
44
48typedef struct FuriThread FuriThread;
49
52
56typedef void* FuriThreadId;
57
66typedef int32_t (*FuriThreadCallback)(void* context);
67
78typedef void (*FuriThreadStdoutWriteCallback)(const char* data, size_t size);
79
91typedef void (*FuriThreadStateCallback)(FuriThread* thread, FuriThreadState state, void* context);
92
103typedef bool (*FuriThreadSignalCallback)(uint32_t signal, void* arg, void* context);
104
111
129 const char* name,
130 uint32_t stack_size,
131 FuriThreadCallback callback,
132 void* context);
133
144 const char* name,
145 uint32_t stack_size,
146 FuriThreadCallback callback,
147 void* context);
148
158void furi_thread_free(FuriThread* thread);
159
168void furi_thread_set_name(FuriThread* thread, const char* name);
169
181void furi_thread_set_appid(FuriThread* thread, const char* appid);
182
192void furi_thread_set_stack_size(FuriThread* thread, size_t stack_size);
193
203
212void furi_thread_set_context(FuriThread* thread, void* context);
213
223
231
238
245
255
264void furi_thread_set_state_context(FuriThread* thread, void* context);
265
273
284 FuriThread* thread,
286 void* context);
287
295
303bool furi_thread_signal(const FuriThread* thread, uint32_t signal, void* arg);
304
312void furi_thread_start(FuriThread* thread);
313
325bool furi_thread_join(FuriThread* thread);
326
334
343
352
362
374
381
388
392void furi_thread_yield(void);
393
403uint32_t furi_thread_flags_set(FuriThreadId thread_id, uint32_t flags);
404
411uint32_t furi_thread_flags_clear(uint32_t flags);
412
417uint32_t furi_thread_flags_get(void);
418
429uint32_t furi_thread_flags_wait(uint32_t flags, uint32_t options, uint32_t timeout);
430
438bool furi_thread_enumerate(FuriThreadList* thread_list);
439
446const char* furi_thread_get_name(FuriThreadId thread_id);
447
454const char* furi_thread_get_appid(FuriThreadId thread_id);
455
462uint32_t furi_thread_get_stack_space(FuriThreadId thread_id);
463
470
476
483size_t furi_thread_stdout_write(const char* data, size_t size);
484
490int32_t furi_thread_stdout_flush(void);
491
499void furi_thread_suspend(FuriThreadId thread_id);
500
506void furi_thread_resume(FuriThreadId thread_id);
507
515
516#ifdef __cplusplus
517}
518#endif
Definition thread.c:33
bool furi_thread_join(FuriThread *thread)
Wait for a FuriThread to exit.
Definition thread.c:391
void furi_thread_enable_heap_trace(FuriThread *thread)
Enable heap usage tracing for a FuriThread.
Definition thread.c:414
void furi_thread_set_stack_size(FuriThread *thread, size_t stack_size)
Set the stack size of a FuriThread instance.
Definition thread.c:273
uint32_t furi_thread_get_stack_space(FuriThreadId thread_id)
Get thread stack watermark.
Definition thread.c:698
FuriThreadPriority furi_thread_get_priority(FuriThread *thread)
Get the priority of a FuriThread.
Definition thread.c:309
FuriThreadPriority furi_thread_get_current_priority(void)
Get the priority of the current FuriThread.
Definition thread.c:320
FuriThread * furi_thread_alloc_ex(const char *name, uint32_t stack_size, FuriThreadCallback callback, void *context)
Create a FuriThread instance w/ extra parameters.
Definition thread.c:220
void furi_thread_set_name(FuriThread *thread, const char *name)
Set the name of a FuriThread instance.
Definition thread.c:251
void furi_thread_suspend(FuriThreadId thread_id)
Suspend a thread.
Definition thread.c:775
bool(* FuriThreadSignalCallback)(uint32_t signal, void *arg, void *context)
Signal handler callback function pointer type.
Definition thread.h:103
uint32_t furi_thread_flags_set(FuriThreadId thread_id, uint32_t flags)
Set the thread flags of a FuriThread.
Definition thread.c:459
FuriThreadState
Enumeration of possible FuriThread states.
Definition thread.h:23
@ FuriThreadStateRunning
Thread is running.
Definition thread.h:27
@ FuriThreadStateStopping
Thread is stopping.
Definition thread.h:25
@ FuriThreadStateStarting
Thread is starting.
Definition thread.h:26
@ FuriThreadStateStopped
Thread is stopped and is safe to release.
Definition thread.h:24
void(* FuriThreadStdoutWriteCallback)(const char *data, size_t size)
Standard output callback function pointer type.
Definition thread.h:78
uint32_t furi_thread_flags_get(void)
Get the thread flags of the current FuriThread.
Definition thread.c:515
FuriThread * furi_thread_get_current(void)
Get the FuriThread instance associated with the current thread.
Definition thread.c:442
size_t furi_thread_stdout_write(const char *data, size_t size)
Write data to buffered standard output.
Definition thread.c:743
uint32_t furi_thread_flags_clear(uint32_t flags)
Clear the thread flags of the current FuriThread.
Definition thread.c:486
void furi_thread_resume(FuriThreadId thread_id)
Resume a thread.
Definition thread.c:783
const char * furi_thread_get_name(FuriThreadId thread_id)
Get the name of a thread based on its unique identifier.
Definition thread.c:671
void furi_thread_set_context(FuriThread *thread, void *context)
Set the callback function context.
Definition thread.c:296
bool furi_thread_enumerate(FuriThreadList *thread_list)
Enumerate all threads.
Definition thread.c:622
uint32_t furi_thread_flags_wait(uint32_t flags, uint32_t options, uint32_t timeout)
Wait for some thread flags to be set.
Definition thread.c:533
size_t furi_thread_get_heap_size(FuriThread *thread)
Get heap usage by a FuriThread instance.
Definition thread.c:426
FuriThreadId furi_thread_get_current_id(void)
Get the unique identifier of the current FuriThread.
Definition thread.c:438
void furi_thread_set_state_context(FuriThread *thread, void *context)
Set the state change callback context.
Definition thread.c:330
FuriThreadSignalCallback furi_thread_get_signal_callback(const FuriThread *thread)
Get a signal callback for a FuriThread instance.
Definition thread.c:352
FuriThreadPriority
Enumeration of possible FuriThread priorities.
Definition thread.h:33
@ FuriThreadPriorityLowest
Lowest.
Definition thread.h:36
@ FuriThreadPriorityNormal
Normal, system default.
Definition thread.h:38
@ FuriThreadPriorityHigh
High.
Definition thread.h:39
@ FuriThreadPriorityHighest
Highest.
Definition thread.h:40
@ FuriThreadPriorityLow
Low.
Definition thread.h:37
@ FuriThreadPriorityInit
Init System Thread Priority.
Definition thread.h:35
@ FuriThreadPriorityIdle
Idle priority.
Definition thread.h:34
@ FuriThreadPriorityIsr
Deferred ISR (highest possible)
Definition thread.h:41
FuriThread * furi_thread_alloc_service(const char *name, uint32_t stack_size, FuriThreadCallback callback, void *context)
Create a FuriThread instance (service mode).
Definition thread.c:200
void furi_thread_set_stdout_callback(FuriThreadStdoutWriteCallback callback)
Set standard output callback for the current thread.
Definition thread.c:730
struct FuriThreadList FuriThreadList
FuriThreadList type.
Definition thread.h:51
void furi_thread_set_callback(FuriThread *thread, FuriThreadCallback callback)
Set the user callback function to be executed in a FuriThread.
Definition thread.c:290
FuriThreadState furi_thread_get_state(FuriThread *thread)
Get the state of a FuriThread isntance.
Definition thread.c:336
void furi_thread_set_appid(FuriThread *thread, const char *appid)
Set the application ID of a FuriThread instance.
Definition thread.c:262
void furi_thread_yield(void)
Return control to the scheduler.
Definition thread.c:447
void furi_thread_free(FuriThread *thread)
Delete a FuriThread instance.
Definition thread.c:233
int32_t furi_thread_get_return_code(FuriThread *thread)
Get the return code of a FuriThread instance.
Definition thread.c:432
void furi_thread_set_priority(FuriThread *thread, FuriThreadPriority priority)
Set the priority of a FuriThread.
Definition thread.c:302
FuriThreadStdoutWriteCallback furi_thread_get_stdout_callback(void)
Get the standard output callback for the current thead.
Definition thread.c:737
void * FuriThreadId
Unique thread identifier type (used by the OS kernel).
Definition thread.h:56
int32_t furi_thread_stdout_flush(void)
Flush buffered data to standard output.
Definition thread.c:768
void furi_thread_set_signal_callback(FuriThread *thread, FuriThreadSignalCallback callback, void *context)
Set a signal handler callback for a FuriThread instance.
Definition thread.c:341
const char * furi_thread_get_appid(FuriThreadId thread_id)
Get the application id of a thread based on its unique identifier.
Definition thread.c:684
void(* FuriThreadStateCallback)(FuriThread *thread, FuriThreadState state, void *context)
State change callback function pointer type.
Definition thread.h:91
void furi_thread_set_state_callback(FuriThread *thread, FuriThreadStateCallback callback)
Set the callback function to be executed upon a state thransition of a FuriThread.
Definition thread.c:324
FuriThreadId furi_thread_get_id(FuriThread *thread)
Get the unique identifier of a FuriThread instance.
Definition thread.c:409
int32_t(* FuriThreadCallback)(void *context)
Thread callback function pointer type.
Definition thread.h:66
FuriThread * furi_thread_alloc(void)
Create a FuriThread instance.
Definition thread.c:192
void furi_thread_disable_heap_trace(FuriThread *thread)
Disable heap usage tracing for a FuriThread.
Definition thread.c:420
bool furi_thread_signal(const FuriThread *thread, uint32_t signal, void *arg)
Send a signal to a FuriThread instance.
Definition thread.c:358
void furi_thread_set_current_priority(FuriThreadPriority priority)
Set the priority of the current FuriThread.
Definition thread.c:315
void furi_thread_start(FuriThread *thread)
Start a FuriThread instance.
Definition thread.c:370
bool furi_thread_is_suspended(FuriThreadId thread_id)
Test if a thread is suspended.
Definition thread.c:795