mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-07-12 23:48:10 -07:00
Merge remote-tracking branch 'ofw/dev' into mntm-dev
This commit is contained in:
+32
-12
@@ -1,7 +1,8 @@
|
||||
#include "thread.h"
|
||||
#include "thread_i.h"
|
||||
#include "thread_list_i.h"
|
||||
#include "timer.h"
|
||||
#include "kernel.h"
|
||||
#include "message_queue.h"
|
||||
#include "memmgr.h"
|
||||
#include "memmgr_heap.h"
|
||||
#include "check.h"
|
||||
@@ -69,6 +70,8 @@ static_assert(offsetof(FuriThread, container) == 0);
|
||||
// Our idle priority should be equal to the one from FreeRTOS
|
||||
static_assert(FuriThreadPriorityIdle == tskIDLE_PRIORITY);
|
||||
|
||||
static FuriMessageQueue* furi_thread_scrub_message_queue = NULL;
|
||||
|
||||
static size_t __furi_thread_stdout_write(FuriThread* thread, const char* data, size_t size);
|
||||
static int32_t __furi_thread_stdout_flush(FuriThread* thread);
|
||||
|
||||
@@ -127,7 +130,9 @@ static void furi_thread_body(void* context) {
|
||||
|
||||
furi_thread_set_state(thread, FuriThreadStateStopping);
|
||||
|
||||
vTaskDelete(NULL);
|
||||
furi_message_queue_put(furi_thread_scrub_message_queue, &thread, FuriWaitForever);
|
||||
|
||||
vTaskSuspend(NULL);
|
||||
furi_thread_catch();
|
||||
}
|
||||
|
||||
@@ -161,6 +166,31 @@ static void furi_thread_init_common(FuriThread* thread) {
|
||||
}
|
||||
}
|
||||
|
||||
void furi_thread_init(void) {
|
||||
furi_thread_scrub_message_queue = furi_message_queue_alloc(8, sizeof(FuriThread*));
|
||||
}
|
||||
|
||||
void furi_thread_scrub(void) {
|
||||
FuriThread* thread_to_scrub = NULL;
|
||||
while(true) {
|
||||
furi_check(
|
||||
furi_message_queue_get(
|
||||
furi_thread_scrub_message_queue, &thread_to_scrub, FuriWaitForever) ==
|
||||
FuriStatusOk);
|
||||
|
||||
TaskHandle_t task = (TaskHandle_t)thread_to_scrub;
|
||||
|
||||
// Delete task: FreeRTOS will remove task from all lists where it may be
|
||||
vTaskDelete(task);
|
||||
// Sanity check: ensure that local storage is ours and clear it
|
||||
furi_check(pvTaskGetThreadLocalStoragePointer(task, 0) == thread_to_scrub);
|
||||
vTaskSetThreadLocalStoragePointer(task, 0, NULL);
|
||||
|
||||
// Deliver thread stopped callback
|
||||
furi_thread_set_state(thread_to_scrub, FuriThreadStateStopped);
|
||||
}
|
||||
}
|
||||
|
||||
FuriThread* furi_thread_alloc(void) {
|
||||
FuriThread* thread = malloc(sizeof(FuriThread));
|
||||
|
||||
@@ -360,16 +390,6 @@ void furi_thread_start(FuriThread* thread) {
|
||||
&thread->container) == (TaskHandle_t)thread);
|
||||
}
|
||||
|
||||
void furi_thread_cleanup_tcb_event(TaskHandle_t task) {
|
||||
FuriThread* thread = pvTaskGetThreadLocalStoragePointer(task, 0);
|
||||
if(thread) {
|
||||
// clear thread local storage
|
||||
vTaskSetThreadLocalStoragePointer(task, 0, NULL);
|
||||
furi_check(thread == (FuriThread*)task);
|
||||
furi_thread_set_state(thread, FuriThreadStateStopped);
|
||||
}
|
||||
}
|
||||
|
||||
bool furi_thread_join(FuriThread* thread) {
|
||||
furi_check(thread);
|
||||
// Cannot join a service thread
|
||||
|
||||
Reference in New Issue
Block a user