Skip to content

Commit

Permalink
Fix shutdown ordering in DeviceControllerSystemState::Shutdown (#22048)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Aug 25, 2023
1 parent d416a32 commit 415cfa8
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/controller/CHIPDeviceControllerFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,19 +419,6 @@ void DeviceControllerSystemState::Shutdown()
mTransportMgr = nullptr;
}

#if CONFIG_DEVICE_LAYER
//
// We can safely call PlatformMgr().Shutdown(), which like DeviceController::Shutdown(),
// expects to be called with external thread synchronization and will not try to acquire the
// stack lock.
//
// Actually stopping the event queue is a separable call that applications will have to sequence.
// Consumers are expected to call PlaformMgr().StopEventLoopTask() before calling
// DeviceController::Shutdown() in the CONFIG_DEVICE_LAYER configuration
//
DeviceLayer::PlatformMgr().Shutdown();
#endif

if (mExchangeMgr != nullptr)
{
mExchangeMgr->Shutdown();
Expand Down Expand Up @@ -483,6 +470,19 @@ void DeviceControllerSystemState::Shutdown()
// so that SetupController/Commissioner can use it
mFabrics = nullptr;
}

#if CONFIG_DEVICE_LAYER
//
// We can safely call PlatformMgr().Shutdown(), which like DeviceController::Shutdown(),
// expects to be called with external thread synchronization and will not try to acquire the
// stack lock.
//
// Actually stopping the event queue is a separable call that applications will have to sequence.
// Consumers are expected to call PlaformMgr().StopEventLoopTask() before calling
// DeviceController::Shutdown() in the CONFIG_DEVICE_LAYER configuration
//
DeviceLayer::PlatformMgr().Shutdown();
#endif
}

} // namespace Controller
Expand Down

0 comments on commit 415cfa8

Please sign in to comment.