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
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
485
492
499
506
515size_t furi_thread_stdout_write(const char* data, size_t size);
516
522int32_t furi_thread_stdout_flush(void);
523
533size_t furi_thread_stdin_read(char* buffer, size_t size, FuriWait timeout);
534
545void furi_thread_stdin_unread(char* buffer, size_t size);
546
554void furi_thread_suspend(FuriThreadId thread_id);
555
561void furi_thread_resume(FuriThreadId thread_id);
562
570
571#ifdef __cplusplus
572}
573#endif
Definition thread.c:38
bool furi_thread_join(FuriThread *thread)
Wait for a FuriThread to exit.
Definition thread.c:399
void furi_thread_enable_heap_trace(FuriThread *thread)
Enable heap usage tracing for a FuriThread.
Definition thread.c:422
void furi_thread_set_stack_size(FuriThread *thread, size_t stack_size)
Set the stack size of a FuriThread instance.
Definition thread.c:281
uint32_t furi_thread_get_stack_space(FuriThreadId thread_id)
Get thread stack watermark.
Definition thread.c:706
FuriThreadPriority furi_thread_get_priority(FuriThread *thread)
Get the priority of a FuriThread.
Definition thread.c:317
FuriThreadPriority furi_thread_get_current_priority(void)
Get the priority of the current FuriThread.
Definition thread.c:328
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:227
void furi_thread_set_name(FuriThread *thread, const char *name)
Set the name of a FuriThread instance.
Definition thread.c:259
void furi_thread_suspend(FuriThreadId thread_id)
Suspend a thread.
Definition thread.c:831
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:820
uint32_t furi_thread_flags_set(FuriThreadId thread_id, uint32_t flags)
Set the thread flags of a FuriThread.
Definition thread.c:467
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
FuriThreadStdinReadCallback furi_thread_get_stdin_callback(void)
Get the standard input callback for the current thead.
Definition thread.c:753
uint32_t furi_thread_flags_get(void)
Get the thread flags of the current FuriThread.
Definition thread.c:523
void furi_thread_set_stdout_callback(FuriThreadStdoutWriteCallback callback, void *context)
Set standard output callback for the current thread.
Definition thread.c:759
FuriThread * furi_thread_get_current(void)
Get the FuriThread instance associated with the current thread.
Definition thread.c:450
size_t furi_thread_stdout_write(const char *data, size_t size)
Write data to buffered standard output.
Definition thread.c:774
size_t furi_thread_stdin_read(char *buffer, size_t size, FuriWait timeout)
Read data from the standard input.
Definition thread.c:806
uint32_t furi_thread_flags_clear(uint32_t flags)
Clear the thread flags of the current FuriThread.
Definition thread.c:494
void furi_thread_resume(FuriThreadId thread_id)
Resume a thread.
Definition thread.c:839
const char * furi_thread_get_name(FuriThreadId thread_id)
Get the name of a thread based on its unique identifier.
Definition thread.c:679
void furi_thread_set_context(FuriThread *thread, void *context)
Set the callback function context.
Definition thread.c:304
bool furi_thread_enumerate(FuriThreadList *thread_list)
Enumerate all threads.
Definition thread.c:630
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:541
size_t furi_thread_get_heap_size(FuriThread *thread)
Get heap usage by a FuriThread instance.
Definition thread.c:434
FuriThreadId furi_thread_get_current_id(void)
Get the unique identifier of the current FuriThread.
Definition thread.c:446
void furi_thread_set_stdin_callback(FuriThreadStdinReadCallback callback, void *context)
Set standard input callback for the current thread.
Definition thread.c:767
void furi_thread_set_state_context(FuriThread *thread, void *context)
Set the state change callback context.
Definition thread.c:338
FuriThreadSignalCallback furi_thread_get_signal_callback(const FuriThread *thread)
Get a signal callback for a FuriThread instance.
Definition thread.c:360
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:207
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:298
FuriThreadState furi_thread_get_state(FuriThread *thread)
Get the state of a FuriThread isntance.
Definition thread.c:344
void furi_thread_set_appid(FuriThread *thread, const char *appid)
Set the application ID of a FuriThread instance.
Definition thread.c:270
void furi_thread_yield(void)
Return control to the scheduler.
Definition thread.c:455
void furi_thread_free(FuriThread *thread)
Delete a FuriThread instance.
Definition thread.c:240
int32_t furi_thread_get_return_code(FuriThread *thread)
Get the return code of a FuriThread instance.
Definition thread.c:440
void furi_thread_set_priority(FuriThread *thread, FuriThreadPriority priority)
Set the priority of a FuriThread.
Definition thread.c:310
FuriThreadStdoutWriteCallback furi_thread_get_stdout_callback(void)
Get the standard output callback for the current thead.
Definition thread.c:747
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:799
void furi_thread_set_signal_callback(FuriThread *thread, FuriThreadSignalCallback callback, void *context)
Set a signal handler callback for a FuriThread instance.
Definition thread.c:349
const char * furi_thread_get_appid(FuriThreadId thread_id)
Get the application id of a thread based on its unique identifier.
Definition thread.c:692
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:332
FuriThreadId furi_thread_get_id(FuriThread *thread)
Get the unique identifier of a FuriThread instance.
Definition thread.c:417
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:199
void furi_thread_disable_heap_trace(FuriThread *thread)
Disable heap usage tracing for a FuriThread.
Definition thread.c:428
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:366
void furi_thread_set_current_priority(FuriThreadPriority priority)
Set the priority of the current FuriThread.
Definition thread.c:323
void furi_thread_start(FuriThread *thread)
Start a FuriThread instance.
Definition thread.c:378
bool furi_thread_is_suspended(FuriThreadId thread_id)
Test if a thread is suspended.
Definition thread.c:851