@@ -301,6 +301,19 @@ void EventHandler(const DeviceLayer::ChipDeviceEvent * event, intptr_t arg)
301
301
}
302
302
}
303
303
304
+ void StopMainEventLoop ()
305
+ {
306
+ if (gMainLoopImplementation != nullptr )
307
+ {
308
+ gMainLoopImplementation ->SignalSafeStopMainLoop ();
309
+ }
310
+ else
311
+ {
312
+ Server::GetInstance ().GenerateShutDownEvent ();
313
+ PlatformMgr ().ScheduleWork ([](intptr_t ) { PlatformMgr ().StopEventLoopTask (); });
314
+ }
315
+ }
316
+
304
317
void Cleanup ()
305
318
{
306
319
#if CHIP_CONFIG_TRANSPORT_TRACE_ENABLED
@@ -317,17 +330,9 @@ void Cleanup()
317
330
// We should stop using signals for those faults, and move to a different notification
318
331
// means, like a pipe. (see issue #19114)
319
332
#if !defined(ENABLE_CHIP_SHELL)
320
- void StopSignalHandler (int signal)
333
+ void StopSignalHandler (int /* signal */ )
321
334
{
322
- if (gMainLoopImplementation != nullptr )
323
- {
324
- gMainLoopImplementation ->SignalSafeStopMainLoop ();
325
- }
326
- else
327
- {
328
- Server::GetInstance ().GenerateShutDownEvent ();
329
- PlatformMgr ().ScheduleWork ([](intptr_t ) { PlatformMgr ().StopEventLoopTask (); });
330
- }
335
+ StopMainEventLoop ();
331
336
}
332
337
#endif // !defined(ENABLE_CHIP_SHELL)
333
338
@@ -530,7 +535,10 @@ void ChipLinuxAppMainLoop(AppMainLoopImplementation * impl)
530
535
531
536
#if defined(ENABLE_CHIP_SHELL)
532
537
Engine::Root ().Init ();
533
- std::thread shellThread ([]() { Engine::Root ().RunMainLoop (); });
538
+ std::thread shellThread ([]() {
539
+ Engine::Root ().RunMainLoop ();
540
+ StopMainEventLoop ();
541
+ });
534
542
Shell::RegisterCommissioneeCommands ();
535
543
#endif
536
544
initParams.operationalServicePort = CHIP_PORT;
@@ -692,14 +700,15 @@ void ChipLinuxAppMainLoop(AppMainLoopImplementation * impl)
692
700
Server::GetInstance ().Shutdown ();
693
701
694
702
#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
703
+ // Commissioner shutdown call shuts down entire stack, including the platform manager.
695
704
ShutdownCommissioner ();
705
+ #else
706
+ DeviceLayer::PlatformMgr ().Shutdown ();
696
707
#endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
697
708
698
709
#if ENABLE_TRACING
699
710
tracing_setup.StopTracing ();
700
711
#endif
701
712
702
- DeviceLayer::PlatformMgr ().Shutdown ();
703
-
704
713
Cleanup ();
705
714
}
0 commit comments