Skip to content

Commit 4314620

Browse files
mspangandy31415
authored andcommitted
Fix shutdown ordering in DeviceControllerSystemState::Shutdown (#22048)
DeviceControllerSystemState shuts down PlatformMgr before higher level objects that use timers such as ExchangeMgr. This leads to calls into the system layer after it has been shut down. Fix the ordering so that PlatformMgr is shut down last. Co-authored-by: Andrei Litvin <andy314@gmail.com>
1 parent dc6fd0f commit 4314620

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/controller/CHIPDeviceControllerFactory.cpp

+13-13
Original file line numberDiff line numberDiff line change
@@ -419,19 +419,6 @@ void DeviceControllerSystemState::Shutdown()
419419
mTransportMgr = nullptr;
420420
}
421421

422-
#if CONFIG_DEVICE_LAYER
423-
//
424-
// We can safely call PlatformMgr().Shutdown(), which like DeviceController::Shutdown(),
425-
// expects to be called with external thread synchronization and will not try to acquire the
426-
// stack lock.
427-
//
428-
// Actually stopping the event queue is a separable call that applications will have to sequence.
429-
// Consumers are expected to call PlaformMgr().StopEventLoopTask() before calling
430-
// DeviceController::Shutdown() in the CONFIG_DEVICE_LAYER configuration
431-
//
432-
DeviceLayer::PlatformMgr().Shutdown();
433-
#endif
434-
435422
if (mExchangeMgr != nullptr)
436423
{
437424
mExchangeMgr->Shutdown();
@@ -483,6 +470,19 @@ void DeviceControllerSystemState::Shutdown()
483470
// so that SetupController/Commissioner can use it
484471
mFabrics = nullptr;
485472
}
473+
474+
#if CONFIG_DEVICE_LAYER
475+
//
476+
// We can safely call PlatformMgr().Shutdown(), which like DeviceController::Shutdown(),
477+
// expects to be called with external thread synchronization and will not try to acquire the
478+
// stack lock.
479+
//
480+
// Actually stopping the event queue is a separable call that applications will have to sequence.
481+
// Consumers are expected to call PlaformMgr().StopEventLoopTask() before calling
482+
// DeviceController::Shutdown() in the CONFIG_DEVICE_LAYER configuration
483+
//
484+
DeviceLayer::PlatformMgr().Shutdown();
485+
#endif
486486
}
487487

488488
} // namespace Controller

0 commit comments

Comments
 (0)