@@ -32,14 +32,6 @@ static void furi_event_loop_item_notify(FuriEventLoopItem* instance);
3232
3333static bool furi_event_loop_item_is_waiting (FuriEventLoopItem * instance );
3434
35- static void furi_event_loop_process_pending_callbacks (FuriEventLoop * instance ) {
36- for (; !PendingQueue_empty_p (instance -> pending_queue );
37- PendingQueue_pop_back (NULL , instance -> pending_queue )) {
38- const FuriEventLoopPendingQueueItem * item = PendingQueue_back (instance -> pending_queue );
39- item -> callback (item -> context );
40- }
41- }
42-
4335static bool furi_event_loop_signal_callback (uint32_t signal , void * arg , void * context ) {
4436 furi_assert (context );
4537 FuriEventLoop * instance = context ;
@@ -130,12 +122,16 @@ static inline FuriEventLoopProcessStatus
130122 furi_event_loop_unsubscribe (instance , item -> object );
131123 }
132124
125+ instance -> current_item = item ;
126+
133127 if (item -> event & FuriEventLoopEventFlagEdge ) {
134128 status = furi_event_loop_process_edge_event (item );
135129 } else {
136130 status = furi_event_loop_process_level_event (item );
137131 }
138132
133+ instance -> current_item = NULL ;
134+
139135 if (item -> owner == NULL ) {
140136 status = FuriEventLoopProcessStatusFreeLater ;
141137 }
@@ -193,6 +189,14 @@ static void furi_event_loop_process_waiting_list(FuriEventLoop* instance) {
193189 furi_event_loop_sync_flags (instance );
194190}
195191
192+ static void furi_event_loop_process_pending_callbacks (FuriEventLoop * instance ) {
193+ for (; !PendingQueue_empty_p (instance -> pending_queue );
194+ PendingQueue_pop_back (NULL , instance -> pending_queue )) {
195+ const FuriEventLoopPendingQueueItem * item = PendingQueue_back (instance -> pending_queue );
196+ item -> callback (item -> context );
197+ }
198+ }
199+
196200static void furi_event_loop_restore_flags (FuriEventLoop * instance , uint32_t flags ) {
197201 if (flags ) {
198202 xTaskNotifyIndexed (
@@ -203,7 +207,6 @@ static void furi_event_loop_restore_flags(FuriEventLoop* instance, uint32_t flag
203207void furi_event_loop_run (FuriEventLoop * instance ) {
204208 furi_check (instance );
205209 furi_check (instance -> thread_id == furi_thread_get_current_id ());
206-
207210 FuriThread * thread = furi_thread_get_current ();
208211
209212 // Set the default signal callback if none was previously set
@@ -213,9 +216,9 @@ void furi_event_loop_run(FuriEventLoop* instance) {
213216
214217 furi_event_loop_init_tick (instance );
215218
216- while (true) {
217- instance -> state = FuriEventLoopStateIdle ;
219+ instance -> state = FuriEventLoopStateRunning ;
218220
221+ while (true) {
219222 const TickType_t ticks_to_sleep =
220223 MIN (furi_event_loop_get_timer_wait_time (instance ),
221224 furi_event_loop_get_tick_wait_time (instance ));
@@ -224,8 +227,6 @@ void furi_event_loop_run(FuriEventLoop* instance) {
224227 BaseType_t ret = xTaskNotifyWaitIndexed (
225228 FURI_EVENT_LOOP_FLAG_NOTIFY_INDEX , 0 , FuriEventLoopFlagAll , & flags , ticks_to_sleep );
226229
227- instance -> state = FuriEventLoopStateProcessing ;
228-
229230 if (ret == pdTRUE ) {
230231 if (flags & FuriEventLoopFlagStop ) {
231232 instance -> state = FuriEventLoopStateStopped ;
@@ -448,7 +449,7 @@ void furi_event_loop_unsubscribe(FuriEventLoop* instance, FuriEventLoopObject* o
448449 WaitingList_unlink (item );
449450 }
450451
451- if (instance -> state == FuriEventLoopStateProcessing ) {
452+ if (instance -> current_item == item ) {
452453 furi_event_loop_item_free_later (item );
453454 } else {
454455 furi_event_loop_item_free (item );
0 commit comments