@@ -67,7 +67,7 @@ static RpcSystemCallbacks rpc_systems[] = {
67
67
struct RpcSession {
68
68
Rpc * rpc ;
69
69
70
- FuriThread * thread ;
70
+ FuriThreadId thread_id ;
71
71
72
72
RpcHandlerDict_t handlers ;
73
73
FuriStreamBuffer * stream ;
@@ -172,7 +172,7 @@ size_t rpc_session_feed(
172
172
173
173
size_t bytes_sent = furi_stream_buffer_send (session -> stream , encoded_bytes , size , timeout );
174
174
175
- furi_thread_flags_set (furi_thread_get_id ( session -> thread ) , RpcEvtNewData );
175
+ furi_thread_flags_set (session -> thread_id , RpcEvtNewData );
176
176
177
177
return bytes_sent ;
178
178
}
@@ -220,7 +220,7 @@ bool rpc_pb_stream_read(pb_istream_t* istream, pb_byte_t* buf, size_t count) {
220
220
break ;
221
221
} else {
222
222
/* Save disconnect flag and continue reading buffer */
223
- furi_thread_flags_set (furi_thread_get_id ( session -> thread ) , RpcEvtDisconnect );
223
+ furi_thread_flags_set (session -> thread_id , RpcEvtDisconnect );
224
224
}
225
225
} else if (flags & RpcEvtNewData ) {
226
226
// Just wake thread up
@@ -347,35 +347,32 @@ static int32_t rpc_session_worker(void* context) {
347
347
return 0 ;
348
348
}
349
349
350
- static void rpc_session_thread_pending_callback (void * context , uint32_t arg ) {
351
- UNUSED (arg );
352
- RpcSession * session = (RpcSession * )context ;
350
+ static void rpc_session_thread_release_callback (
351
+ FuriThread * thread ,
352
+ FuriThreadState thread_state ,
353
+ void * context ) {
354
+ if (thread_state == FuriThreadStateStopped ) {
355
+ RpcSession * session = (RpcSession * )context ;
353
356
354
- for (size_t i = 0 ; i < COUNT_OF (rpc_systems ); ++ i ) {
355
- if (rpc_systems [i ].free ) {
356
- (rpc_systems [i ].free )(session -> system_contexts [i ]);
357
+ for (size_t i = 0 ; i < COUNT_OF (rpc_systems ); ++ i ) {
358
+ if (rpc_systems [i ].free ) {
359
+ (rpc_systems [i ].free )(session -> system_contexts [i ]);
360
+ }
357
361
}
358
- }
359
- free (session -> system_contexts );
360
- free (session -> decoded_message );
361
- RpcHandlerDict_clear (session -> handlers );
362
- furi_stream_buffer_free (session -> stream );
363
-
364
- furi_mutex_acquire (session -> callbacks_mutex , FuriWaitForever );
365
- if (session -> terminated_callback ) {
366
- session -> terminated_callback (session -> context );
367
- }
368
- furi_mutex_release (session -> callbacks_mutex );
369
-
370
- furi_mutex_free (session -> callbacks_mutex );
371
- furi_thread_join (session -> thread );
372
- furi_thread_free (session -> thread );
373
- free (session );
374
- }
362
+ free (session -> system_contexts );
363
+ free (session -> decoded_message );
364
+ RpcHandlerDict_clear (session -> handlers );
365
+ furi_stream_buffer_free (session -> stream );
366
+
367
+ furi_mutex_acquire (session -> callbacks_mutex , FuriWaitForever );
368
+ if (session -> terminated_callback ) {
369
+ session -> terminated_callback (session -> context );
370
+ }
371
+ furi_mutex_release (session -> callbacks_mutex );
375
372
376
- static void rpc_session_thread_state_callback ( FuriThreadState thread_state , void * context ) {
377
- if ( thread_state == FuriThreadStateStopped ) {
378
- furi_timer_pending_callback ( rpc_session_thread_pending_callback , context , 0 );
373
+ furi_mutex_free ( session -> callbacks_mutex );
374
+ furi_thread_free ( thread );
375
+ free ( session );
379
376
}
380
377
}
381
378
@@ -407,12 +404,14 @@ RpcSession* rpc_session_open(Rpc* rpc, RpcOwner owner) {
407
404
};
408
405
rpc_add_handler (session , PB_Main_stop_session_tag , & rpc_handler );
409
406
410
- session -> thread = furi_thread_alloc_ex ("RpcSessionWorker" , 3072 , rpc_session_worker , session );
407
+ FuriThread * thread =
408
+ furi_thread_alloc_ex ("RpcSessionWorker" , 3072 , rpc_session_worker , session );
409
+ session -> thread_id = furi_thread_get_id (thread );
411
410
412
- furi_thread_set_state_context (session -> thread , session );
413
- furi_thread_set_state_callback (session -> thread , rpc_session_thread_state_callback );
411
+ furi_thread_set_state_context (thread , session );
412
+ furi_thread_set_state_callback (thread , rpc_session_thread_release_callback );
414
413
415
- furi_thread_start (session -> thread );
414
+ furi_thread_start (thread );
416
415
417
416
return session ;
418
417
}
@@ -424,7 +423,7 @@ void rpc_session_close(RpcSession* session) {
424
423
rpc_session_set_send_bytes_callback (session , NULL );
425
424
rpc_session_set_close_callback (session , NULL );
426
425
rpc_session_set_buffer_is_empty_callback (session , NULL );
427
- furi_thread_flags_set (furi_thread_get_id ( session -> thread ) , RpcEvtDisconnect );
426
+ furi_thread_flags_set (session -> thread_id , RpcEvtDisconnect );
428
427
}
429
428
430
429
void rpc_on_system_start (void * p ) {
0 commit comments