mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-04-24 03:29:57 -07:00
Merge remote-tracking branch 'ofw/dev' into mntm-dev
This commit is contained in:
@@ -35,7 +35,7 @@ struct FuriThread {
|
||||
StaticTask_t container;
|
||||
StackType_t* stack_buffer;
|
||||
|
||||
FuriThreadState state;
|
||||
volatile FuriThreadState state;
|
||||
int32_t ret;
|
||||
|
||||
FuriThreadCallback callback;
|
||||
@@ -61,7 +61,6 @@ struct FuriThread {
|
||||
// this ensures that the size of this structure is minimal
|
||||
bool is_service;
|
||||
bool heap_trace_enabled;
|
||||
volatile bool is_active;
|
||||
};
|
||||
|
||||
// IMPORTANT: container MUST be the FIRST struct member
|
||||
@@ -86,7 +85,7 @@ static void furi_thread_set_state(FuriThread* thread, FuriThreadState state) {
|
||||
furi_assert(thread);
|
||||
thread->state = state;
|
||||
if(thread->state_callback) {
|
||||
thread->state_callback(state, thread->state_context);
|
||||
thread->state_callback(thread, state, thread->state_context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,7 +125,7 @@ static void furi_thread_body(void* context) {
|
||||
// flush stdout
|
||||
__furi_thread_stdout_flush(thread);
|
||||
|
||||
furi_thread_set_state(thread, FuriThreadStateStopped);
|
||||
furi_thread_set_state(thread, FuriThreadStateStopping);
|
||||
|
||||
vTaskDelete(NULL);
|
||||
furi_thread_catch();
|
||||
@@ -209,7 +208,6 @@ void furi_thread_free(FuriThread* thread) {
|
||||
furi_check(thread->is_service == false);
|
||||
// Cannot free a non-joined thread
|
||||
furi_check(thread->state == FuriThreadStateStopped);
|
||||
furi_check(!thread->is_active);
|
||||
|
||||
furi_thread_set_name(thread, NULL);
|
||||
furi_thread_set_appid(thread, NULL);
|
||||
@@ -351,8 +349,6 @@ void furi_thread_start(FuriThread* thread) {
|
||||
|
||||
uint32_t stack_depth = thread->stack_size / sizeof(StackType_t);
|
||||
|
||||
thread->is_active = true;
|
||||
|
||||
furi_check(
|
||||
xTaskCreateStatic(
|
||||
furi_thread_body,
|
||||
@@ -370,7 +366,7 @@ void furi_thread_cleanup_tcb_event(TaskHandle_t task) {
|
||||
// clear thread local storage
|
||||
vTaskSetThreadLocalStoragePointer(task, 0, NULL);
|
||||
furi_check(thread == (FuriThread*)task);
|
||||
thread->is_active = false;
|
||||
furi_thread_set_state(thread, FuriThreadStateStopped);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -385,8 +381,8 @@ bool furi_thread_join(FuriThread* thread) {
|
||||
//
|
||||
// If your thread exited, but your app stuck here: some other thread uses
|
||||
// all cpu time, which delays kernel from releasing task handle
|
||||
while(thread->is_active) {
|
||||
furi_delay_ms(10);
|
||||
while(thread->state != FuriThreadStateStopped) {
|
||||
furi_delay_tick(2);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -21,7 +21,8 @@ extern "C" {
|
||||
* Many of the FuriThread functions MUST ONLY be called when the thread is STOPPED.
|
||||
*/
|
||||
typedef enum {
|
||||
FuriThreadStateStopped, /**< Thread is stopped */
|
||||
FuriThreadStateStopped, /**< Thread is stopped and is safe to release */
|
||||
FuriThreadStateStopping, /**< Thread is stopping */
|
||||
FuriThreadStateStarting, /**< Thread is starting */
|
||||
FuriThreadStateRunning, /**< Thread is running */
|
||||
} FuriThreadState;
|
||||
@@ -80,10 +81,11 @@ typedef void (*FuriThreadStdoutWriteCallback)(const char* data, size_t size);
|
||||
*
|
||||
* The function to be used as a state callback MUST follow this signature.
|
||||
*
|
||||
* @param[in] pointer to the FuriThread instance that changed the state
|
||||
* @param[in] state identifier of the state the thread has transitioned to
|
||||
* @param[in,out] context pointer to a user-specified object
|
||||
*/
|
||||
typedef void (*FuriThreadStateCallback)(FuriThreadState state, void* context);
|
||||
typedef void (*FuriThreadStateCallback)(FuriThread* thread, FuriThreadState state, void* context);
|
||||
|
||||
/**
|
||||
* @brief Signal handler callback function pointer type.
|
||||
|
||||
Reference in New Issue
Block a user