All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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
79typedef void (*FuriThreadStdoutWriteCallback)(const char* data, size_t size, void* context);
80
92typedef size_t (
93 *FuriThreadStdinReadCallback)(char* buffer, size_t size, FuriWait timeout, void* context);
94
106typedef void (*FuriThreadStateCallback)(FuriThread* thread, FuriThreadState state, void* context);
107
118typedef bool (*FuriThreadSignalCallback)(uint32_t signal, void* arg, void* context);
119
126
144 const char* name,
145 uint32_t stack_size,
146 FuriThreadCallback callback,
147 void* context);
148
159 const char* name,
160 uint32_t stack_size,
161 FuriThreadCallback callback,
162 void* context);
163
173void furi_thread_free(FuriThread* thread);
174
183void furi_thread_set_name(FuriThread* thread, const char* name);
184
196void furi_thread_set_appid(FuriThread* thread, const char* appid);
197
207void furi_thread_set_stack_size(FuriThread* thread, size_t stack_size);
208
218
227void furi_thread_set_context(FuriThread* thread, void* context);
228
238
246
253
260
270
279void furi_thread_set_state_context(FuriThread* thread, void* context);
280
288
299 FuriThread* thread,
301 void* context);
302
310
318bool furi_thread_signal(const FuriThread* thread, uint32_t signal, void* arg);
319
327void furi_thread_start(FuriThread* thread);
328
340bool furi_thread_join(FuriThread* thread);
341
349
358
367
377
389
396
403
407void furi_thread_yield(void);
408
418uint32_t furi_thread_flags_set(FuriThreadId thread_id, uint32_t flags);
419
426uint32_t furi_thread_flags_clear(uint32_t flags);
427
432uint32_t furi_thread_flags_get(void);
433
444uint32_t furi_thread_flags_wait(uint32_t flags, uint32_t options, uint32_t timeout);
445
453bool furi_thread_enumerate(FuriThreadList* thread_list);
454
461const char* furi_thread_get_name(FuriThreadId thread_id);
462
469const char* furi_thread_get_appid(FuriThreadId thread_id);
470
477uint32_t furi_thread_get_stack_space(FuriThreadId thread_id);
478
486
493void furi_thread_get_stdin_callback(FuriThreadStdinReadCallback* callback, void** context);
494
501
508
517size_t furi_thread_stdout_write(const char* data, size_t size);
518
524int32_t furi_thread_stdout_flush(void);
525
535size_t furi_thread_stdin_read(char* buffer, size_t size, FuriWait timeout);
536
547void furi_thread_stdin_unread(char* buffer, size_t size);
548
556void furi_thread_suspend(FuriThreadId thread_id);
557
563void furi_thread_resume(FuriThreadId thread_id);
564
572
573#ifdef __cplusplus
574}
575#endif
Definition thread.c:41
bool furi_thread_join(FuriThread *thread)
Wait for a FuriThread to exit.
Definition thread.c:414
void furi_thread_enable_heap_trace(FuriThread *thread)
Enable heap usage tracing for a FuriThread.
Definition thread.c:437
void furi_thread_set_stack_size(FuriThread *thread, size_t stack_size)
Set the stack size of a FuriThread instance.
Definition thread.c:296
uint32_t furi_thread_get_stack_space(FuriThreadId thread_id)
Get thread stack watermark.
Definition thread.c:724
FuriThreadPriority furi_thread_get_priority(FuriThread *thread)
Get the priority of a FuriThread.
Definition thread.c:332
FuriThreadPriority furi_thread_get_current_priority(void)
Get the priority of the current FuriThread.
Definition thread.c:343
size_t(* FuriThreadStdinReadCallback)(char *buffer, size_t size, FuriWait timeout, void *context)
Standard input callback function pointer type.
Definition thread.h:93
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:242
void furi_thread_set_name(FuriThread *thread, const char *name)
Set the name of a FuriThread instance.
Definition thread.c:274
void furi_thread_suspend(FuriThreadId thread_id)
Suspend a thread.
Definition thread.c:855
bool(* FuriThreadSignalCallback)(uint32_t signal, void *arg, void *context)
Signal handler callback function pointer type.
Definition thread.h:118
void furi_thread_stdin_unread(char *buffer, size_t size)
Puts data back into the standard input buffer.
Definition thread.c:844
uint32_t furi_thread_flags_set(FuriThreadId thread_id, uint32_t flags)
Set the thread flags of a FuriThread.
Definition thread.c:482
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
uint32_t furi_thread_flags_get(void)
Get the thread flags of the current FuriThread.
Definition thread.c:541
void furi_thread_set_stdout_callback(FuriThreadStdoutWriteCallback callback, void *context)
Set standard output callback for the current thread.
Definition thread.c:783
FuriThread * furi_thread_get_current(void)
Get the FuriThread instance associated with the current thread.
Definition thread.c:465
size_t furi_thread_stdout_write(const char *data, size_t size)
Write data to buffered standard output.
Definition thread.c:798
size_t furi_thread_stdin_read(char *buffer, size_t size, FuriWait timeout)
Read data from the standard input.
Definition thread.c:830
uint32_t furi_thread_flags_clear(uint32_t flags)
Clear the thread flags of the current FuriThread.
Definition thread.c:512
void furi_thread_resume(FuriThreadId thread_id)
Resume a thread.
Definition thread.c:863
const char * furi_thread_get_name(FuriThreadId thread_id)
Get the name of a thread based on its unique identifier.
Definition thread.c:697
void furi_thread_set_context(FuriThread *thread, void *context)
Set the callback function context.
Definition thread.c:319
bool furi_thread_enumerate(FuriThreadList *thread_list)
Enumerate all threads.
Definition thread.c:648
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:559
size_t furi_thread_get_heap_size(FuriThread *thread)
Get heap usage by a FuriThread instance.
Definition thread.c:449
FuriThreadId furi_thread_get_current_id(void)
Get the unique identifier of the current FuriThread.
Definition thread.c:461
void furi_thread_set_stdin_callback(FuriThreadStdinReadCallback callback, void *context)
Set standard input callback for the current thread.
Definition thread.c:791
void furi_thread_set_state_context(FuriThread *thread, void *context)
Set the state change callback context.
Definition thread.c:353
FuriThreadSignalCallback furi_thread_get_signal_callback(const FuriThread *thread)
Get a signal callback for a FuriThread instance.
Definition thread.c:375
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:222
struct FuriThreadList FuriThreadList
FuriThreadList type.
Definition thread.h:51
void furi_thread_get_stdin_callback(FuriThreadStdinReadCallback *callback, void **context)
Get the standard input callback for the current thead.
Definition thread.c:774
void furi_thread_set_callback(FuriThread *thread, FuriThreadCallback callback)
Set the user callback function to be executed in a FuriThread.
Definition thread.c:313
FuriThreadState furi_thread_get_state(FuriThread *thread)
Get the state of a FuriThread isntance.
Definition thread.c:359
void furi_thread_set_appid(FuriThread *thread, const char *appid)
Set the application ID of a FuriThread instance.
Definition thread.c:285
void furi_thread_yield(void)
Return control to the scheduler.
Definition thread.c:470
void furi_thread_get_stdout_callback(FuriThreadStdoutWriteCallback *callback, void **context)
Get the standard output callback for the current thead.
Definition thread.c:765
void furi_thread_free(FuriThread *thread)
Delete a FuriThread instance.
Definition thread.c:255
int32_t furi_thread_get_return_code(FuriThread *thread)
Get the return code of a FuriThread instance.
Definition thread.c:455
void furi_thread_set_priority(FuriThread *thread, FuriThreadPriority priority)
Set the priority of a FuriThread.
Definition thread.c:325
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:823
void furi_thread_set_signal_callback(FuriThread *thread, FuriThreadSignalCallback callback, void *context)
Set a signal handler callback for a FuriThread instance.
Definition thread.c:364
const char * furi_thread_get_appid(FuriThreadId thread_id)
Get the application id of a thread based on its unique identifier.
Definition thread.c:710
void(* FuriThreadStateCallback)(FuriThread *thread, FuriThreadState state, void *context)
State change callback function pointer type.
Definition thread.h:106
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:347
FuriThreadId furi_thread_get_id(FuriThread *thread)
Get the unique identifier of a FuriThread instance.
Definition thread.c:432
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:214
void furi_thread_disable_heap_trace(FuriThread *thread)
Disable heap usage tracing for a FuriThread.
Definition thread.c:443
void(* FuriThreadStdoutWriteCallback)(const char *data, size_t size, void *context)
Standard output callback function pointer type.
Definition thread.h:79
bool furi_thread_signal(const FuriThread *thread, uint32_t signal, void *arg)
Send a signal to a FuriThread instance.
Definition thread.c:381
void furi_thread_set_current_priority(FuriThreadPriority priority)
Set the priority of the current FuriThread.
Definition thread.c:338
void furi_thread_start(FuriThread *thread)
Start a FuriThread instance.
Definition thread.c:393
bool furi_thread_is_suspended(FuriThreadId thread_id)
Test if a thread is suspended.
Definition thread.c:875