Skip to content

Commit bd05b53

Browse files
Tighten the use of FuriThread* vs FuriThreadId
Event loop and Loader mixed those two, but the fact those are aliases should be an implementation detail. For this reason, thread.c is still allowed to mix them freely.
1 parent 7005648 commit bd05b53

File tree

4 files changed

+38
-24
lines changed

4 files changed

+38
-24
lines changed

applications/services/loader/loader.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ static bool loader_do_signal(Loader* loader, uint32_t signal, void* arg) {
717717

718718
static bool loader_do_get_application_name(Loader* loader, FuriString* name) {
719719
if(loader_is_application_running(loader)) {
720-
furi_string_set(name, furi_thread_get_name(loader->app.thread));
720+
furi_string_set(name, furi_thread_get_name(furi_thread_get_id(loader->app.thread)));
721721
return true;
722722
}
723723

furi/core/event_loop.c

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ FuriEventLoop* furi_event_loop_alloc(void) {
7171
PendingQueue_init(instance->pending_queue);
7272

7373
// Clear notification state and value
74-
xTaskNotifyStateClearIndexed(instance->thread_id, FURI_EVENT_LOOP_FLAG_NOTIFY_INDEX);
75-
ulTaskNotifyValueClearIndexed(
76-
instance->thread_id, FURI_EVENT_LOOP_FLAG_NOTIFY_INDEX, 0xFFFFFFFF);
74+
TaskHandle_t task = (TaskHandle_t)instance->thread_id;
75+
xTaskNotifyStateClearIndexed(task, FURI_EVENT_LOOP_FLAG_NOTIFY_INDEX);
76+
ulTaskNotifyValueClearIndexed(task, FURI_EVENT_LOOP_FLAG_NOTIFY_INDEX, 0xFFFFFFFF);
7777

7878
return instance;
7979
}
@@ -178,18 +178,19 @@ static void furi_event_loop_process_waiting_list(FuriEventLoop* instance) {
178178
static void furi_event_loop_restore_flags(FuriEventLoop* instance, uint32_t flags) {
179179
if(flags) {
180180
xTaskNotifyIndexed(
181-
instance->thread_id, FURI_EVENT_LOOP_FLAG_NOTIFY_INDEX, flags, eSetBits);
181+
(TaskHandle_t)instance->thread_id, FURI_EVENT_LOOP_FLAG_NOTIFY_INDEX, flags, eSetBits);
182182
}
183183
}
184184

185185
void furi_event_loop_run(FuriEventLoop* instance) {
186186
furi_check(instance);
187187
furi_check(instance->thread_id == furi_thread_get_current_id());
188188

189+
FuriThread* thread = furi_thread_get_current();
190+
189191
// Set the default signal callback if none was previously set
190-
if(furi_thread_get_signal_callback(instance->thread_id) == NULL) {
191-
furi_thread_set_signal_callback(
192-
instance->thread_id, furi_event_loop_signal_callback, instance);
192+
if(furi_thread_get_signal_callback(thread) == NULL) {
193+
furi_thread_set_signal_callback(thread, furi_event_loop_signal_callback, instance);
193194
}
194195

195196
furi_event_loop_init_tick(instance);
@@ -233,16 +234,19 @@ void furi_event_loop_run(FuriEventLoop* instance) {
233234
}
234235

235236
// Disable the default signal callback
236-
if(furi_thread_get_signal_callback(instance->thread_id) == furi_event_loop_signal_callback) {
237-
furi_thread_set_signal_callback(instance->thread_id, NULL, NULL);
237+
if(furi_thread_get_signal_callback(thread) == furi_event_loop_signal_callback) {
238+
furi_thread_set_signal_callback(thread, NULL, NULL);
238239
}
239240
}
240241

241242
void furi_event_loop_stop(FuriEventLoop* instance) {
242243
furi_check(instance);
243244

244245
xTaskNotifyIndexed(
245-
instance->thread_id, FURI_EVENT_LOOP_FLAG_NOTIFY_INDEX, FuriEventLoopFlagStop, eSetBits);
246+
(TaskHandle_t)instance->thread_id,
247+
FURI_EVENT_LOOP_FLAG_NOTIFY_INDEX,
248+
FuriEventLoopFlagStop,
249+
eSetBits);
246250
}
247251

248252
/*
@@ -265,7 +269,10 @@ void furi_event_loop_pend_callback(
265269
PendingQueue_push_front(instance->pending_queue, item);
266270

267271
xTaskNotifyIndexed(
268-
instance->thread_id, FURI_EVENT_LOOP_FLAG_NOTIFY_INDEX, FuriEventLoopFlagPending, eSetBits);
272+
(TaskHandle_t)instance->thread_id,
273+
FURI_EVENT_LOOP_FLAG_NOTIFY_INDEX,
274+
FuriEventLoopFlagPending,
275+
eSetBits);
269276
}
270277

271278
/*
@@ -473,7 +480,10 @@ static void furi_event_loop_item_notify(FuriEventLoopItem* instance) {
473480
FURI_CRITICAL_EXIT();
474481

475482
xTaskNotifyIndexed(
476-
owner->thread_id, FURI_EVENT_LOOP_FLAG_NOTIFY_INDEX, FuriEventLoopFlagEvent, eSetBits);
483+
(TaskHandle_t)owner->thread_id,
484+
FURI_EVENT_LOOP_FLAG_NOTIFY_INDEX,
485+
FuriEventLoopFlagEvent,
486+
eSetBits);
477487
}
478488

479489
static bool furi_event_loop_item_is_waiting(FuriEventLoopItem* instance) {

furi/core/event_loop_timer.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ static void furi_event_loop_timer_enqueue_request(
6565
TimerQueue_push_back(instance->timer_queue, timer);
6666

6767
xTaskNotifyIndexed(
68-
instance->thread_id, FURI_EVENT_LOOP_FLAG_NOTIFY_INDEX, FuriEventLoopFlagTimer, eSetBits);
68+
(TaskHandle_t)instance->thread_id,
69+
FURI_EVENT_LOOP_FLAG_NOTIFY_INDEX,
70+
FuriEventLoopFlagTimer,
71+
eSetBits);
6972
}
7073

7174
/*

furi/core/thread.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ static void furi_thread_body(void* context) {
9797
furi_thread_set_state(thread, FuriThreadStateRunning);
9898

9999
if(thread->heap_trace_enabled == true) {
100-
memmgr_heap_enable_thread_trace(thread);
100+
memmgr_heap_enable_thread_trace((FuriThreadId)thread);
101101
}
102102

103103
thread->ret = thread->callback(thread->context);
@@ -106,14 +106,14 @@ static void furi_thread_body(void* context) {
106106

107107
if(thread->heap_trace_enabled == true) {
108108
furi_delay_ms(33);
109-
thread->heap_size = memmgr_heap_get_thread_memory(thread);
109+
thread->heap_size = memmgr_heap_get_thread_memory((FuriThreadId)thread);
110110
furi_log_print_format(
111111
thread->heap_size ? FuriLogLevelError : FuriLogLevelInfo,
112112
TAG,
113113
"%s allocation balance: %zu",
114114
thread->name ? thread->name : "Thread",
115115
thread->heap_size);
116-
memmgr_heap_disable_thread_trace(thread);
116+
memmgr_heap_disable_thread_trace((FuriThreadId)thread);
117117
}
118118

119119
furi_check(thread->state == FuriThreadStateRunning);
@@ -275,7 +275,7 @@ void furi_thread_set_priority(FuriThread* thread, FuriThreadPriority priority) {
275275

276276
FuriThreadPriority furi_thread_get_priority(FuriThread* thread) {
277277
furi_check(thread);
278-
TaskHandle_t hTask = furi_thread_get_id(thread);
278+
TaskHandle_t hTask = (TaskHandle_t)thread;
279279
return (FuriThreadPriority)uxTaskPriorityGet(hTask);
280280
}
281281

@@ -390,7 +390,7 @@ bool furi_thread_join(FuriThread* thread) {
390390

391391
FuriThreadId furi_thread_get_id(FuriThread* thread) {
392392
furi_check(thread);
393-
return thread;
393+
return (FuriThreadId)thread;
394394
}
395395

396396
void furi_thread_enable_heap_trace(FuriThread* thread) {
@@ -418,7 +418,7 @@ int32_t furi_thread_get_return_code(FuriThread* thread) {
418418
}
419419

420420
FuriThreadId furi_thread_get_current_id(void) {
421-
return xTaskGetCurrentTaskHandle();
421+
return (FuriThreadId)xTaskGetCurrentTaskHandle();
422422
}
423423

424424
FuriThread* furi_thread_get_current(void) {
@@ -624,15 +624,16 @@ bool furi_thread_enumerate(FuriThreadList* thread_list) {
624624
FuriThreadListItem* item =
625625
furi_thread_list_get_or_insert(thread_list, (FuriThread*)task[i].xHandle);
626626

627-
item->thread = (FuriThreadId)task[i].xHandle;
628-
item->app_id = furi_thread_get_appid(item->thread);
627+
FuriThreadId thread_id = (FuriThreadId)task[i].xHandle;
628+
item->thread = (FuriThread*)thread_id;
629+
item->app_id = furi_thread_get_appid(thread_id);
629630
item->name = task[i].pcTaskName;
630631
item->priority = task[i].uxCurrentPriority;
631632
item->stack_address = (uint32_t)tcb->pxStack;
632-
size_t thread_heap = memmgr_heap_get_thread_memory(item->thread);
633+
size_t thread_heap = memmgr_heap_get_thread_memory(thread_id);
633634
item->heap = thread_heap == MEMMGR_HEAP_UNKNOWN ? 0u : thread_heap;
634635
item->stack_size = (tcb->pxEndOfStack - tcb->pxStack + 1) * sizeof(StackType_t);
635-
item->stack_min_free = furi_thread_get_stack_space(item->thread);
636+
item->stack_min_free = furi_thread_get_stack_space(thread_id);
636637
item->state = furi_thread_state_name(task[i].eCurrentState);
637638
item->counter_previous = item->counter_current;
638639
item->counter_current = task[i].ulRunTimeCounter;

0 commit comments

Comments
 (0)